Elasticsearch 查询
查看索引列表: http://127.0.0.1:9200/_cat/indices?v
------------恢复内容开始------------
查看索引列表: http://127.0.0.1:9200/_cat/indices?v
新建索引:put http://127.0.0.1:9200/shopping
新建内容 :post http://127.0.0.1:9200/shopping/_doc
新建定义ID数据: post http://127.0.0.1:9200/shopping/_doc/id
查询所有:get http://127.0.0.1:9200/shopping/_search
覆盖内容: put http://127.0.0.1:9200/shopping/_doc/id
局部更新:post http://127.0.0.1:9200/shopping/_update/1001
{
"doc":{
"title":"华为手机"
}
}
条件查询
get http://127.0.0.1:9200/shopping/_search?q=category:小米
get http://127.0.0.1:9200/shopping/_search
局部查询 {
"query":{
"match":{
"category":"小米"
}
}
}
全量查询
{
"query":{
"match_all ":{
}
},
"from":0,
"size":2,
"_source":["title"], //返回列
"sort":{
"price":{
"order":"desc"
}
}
}
多条件查询,范围查询
"query":{
"bool":{
"must":[ //多条件满足 should //单条件满足
{
"match":{
"category":"小米"
}
}
],
"filter":{
"range":{
"price":{
"gt":5000
}
}
}
}
}
全文匹配,完全匹配,高亮匹配
"query":{
"match_phrase":{
" category":"xx"
}
},
"highlight":{
"fields":{
"category":{}
}
聚合查询
"aggs":{
"price_group":{ // price_avg
"terms":{ //avg
"field":"price"
}
}
},
"size":0
映射关系
get http://127.0.0.1:9200/user/_mapping
"properties":{
"name":{
"type":"text",
"index":true //可被索引查询
},
"sex":{
"type":"keyword", //非模糊查询
"index":false //不可被索引查询
}
------------恢复内容结束------------