ES(七) Demo-商品搜索

一、引

    经过上述章节的阐述,最后实操一个小小的CRUD Demo,感受一下,ES为我们带来的便利。

二、创建索引

PUT demo_goods

    "mappings": {   
        "doc":{     
            "properties":{         
                "category":{           
                    "type":"keyword"         
                },         
                "spu_name":{           
                    "type":"text",           
                    "analyzer":"ik_smart"         
                },         
                "title":{           
                    "type":"text",           
                    "analyzer":"ik_smart"         
                },         
                "price":{           
                    "type":"scaled_float",           
                    "scaling_factor": 100         
                },         
                "img":{           
                    "type":"keyword",           
                    "index":false         
                }     
            }   
        } 
    }
}

创建索引

三、插入记录

POST demo_goods/doc/
{
  "category":"耳机",
  "spu_name":"Airpods",
  "title":"Apple Airpods配充电盒 Apple蓝牙耳机 适用iphone/ipad/Apple Watch",
  "price":1146.00,
  "img":"xxx.jpg"
}

POST demo_goods/doc/
{
  "category":"耳机",
  "spu_name":"网易云音乐 ME05TWS",
  "title":"网易云音乐【零感佩戴】 真无线蓝牙耳机双耳 半入耳式运动跑步游戏耳机通用于苹果华为小米手机",
  "price":159.00,
  "img":"xxx.jpg"
}

POST demo_goods/doc/
{
  "category":"耳机",
  "spu_name":"漫步者 LolliPods",
  "title":"漫步者(EDIFIER) LolliPods真无线蓝牙耳机 半入耳式耳机 音乐耳机 通用苹果华为小米手机 萝莉pods",
  "price":238.00,
  "img":"xxx.jpg"
}

POST demo_goods/doc/
{
  "category":"白酒",
  "spu_name":"茅台 飞天",
  "title":"茅台飞天 酱香型白酒",
  "price":999.00,
  "img":"xxx.jpg"
}

POST demo_goods/doc/
{
  "category":"白酒",
  "spu_name":"五粮液第八代",
  "title":"五粮液52度普五第八代款",
  "price":1399.00,
  "img":"xxx.jpg"
}

插入记录

四、查询记录

GET demo_goods/_search
{
  "query": {
    "multi_match": {
       "query" : "音乐耳机",
       "fields": ["spu_name","title"]
    }
  }
}

GET /demo_goods/_search
{
"query": { "match_all": {} },
"from": 0,
"size": 20
}

GET demo_goods/doc/ShL0LXcBUkVyXtlB_mOR

查询记录

五、更新记录

POST demo_goods/doc/UBItLncBUkVyXtlBk2O0
{
  "category": "白酒",
  "spu_name": "五粮液第八代",
  "title": "五粮液52度普五第八代款",
  "price": 1399,
  "img": "xxx.jpg"
}

更新记录

六、删除记录

DELETE demo_goods/doc/UxI7LncBUkVyXtlBZGOO

POST demo_goods/_delete_by_query
{
  "query": {
    "match_all": {}
  }
}

删除记录

七、总结

    附上我翻译成Java代码所用的依赖...

   
       io.searchbox
       jest
       5.3.3
    

     ES以及其生态,还远不于此。上官网吧:https://www.elastic.co





ES(六) ElasticSearch搜索原理


你可能感兴趣的:(ES(七) Demo-商品搜索)