elasticsearch 的使用 查询操作

elasticsearch的查询方法

创建索引

PUT test1

添加数据,可以指定id

POST test1/_doc/2 { "name":"刘备", "age":54, "location":"蜀国" }

查询操作两种方法

· 第一种
GET test1/_search?q=location="吴国"

· 第二种DSL查询方式
GET test1/_search { "query": { "match": { "location": "吴国" } } }
这种方式查询的是对location进行了分词,吴国分为了三个:吴、国、吴国
如果加上.keyword 则表示对location该词语不进行分词 完全搜索
GET test1/_search { "query": { "match": { "location.keyword": "吴国" } } }

还有一个类似于mysql中select * from tables;

类似于select * from tables;

GET test1/_search { "query": { "match_all": {} } }

查询结果排序

GET test1/_search { "query": { "match": { "location.keyword": "蜀国" } }, "sort": [ { "age": { "order": "desc" } } ] }

如果是要选择升序,就使用asc

posted @ 2021-12-04 11:32  竹石2020  阅读(201)  评论(0编辑  收藏  举报