elasticsearch中的布尔查询

elasticsearch中的布尔查询

例如查询年龄是25岁,输入王者荣耀的英雄
GET test1/_search { "query": { "bool": { "must": [ { "match": { "age": "25" } }, { "match": { "location": "王者" } } ] } } }

查询年龄为25或者来自王者荣耀的人物

GET test1/_search { "query": { "bool": { "should": [ { "match": { "age": 25 } }, { "match": { "location.keyword": "王者荣耀" } } ] } } }

查询年龄大于50,且属于魏国的人物。

`GET test1/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"location.keyword": "魏国"
}
}
],
"filter": [
{
"range": {
"age": {
"gt": 50

        }
      }
    }
  ]
}

}
}`

查询的方式方法有以下几种。

对查询结构进行过滤

`GET test1/_search
{
"query": {
"match_all": {}
},
"_source": ["location","age"]

}
`

高亮显示,对结果进行高亮显示

GET test1/_search { "query": { "match": { "location": "英雄" } }, "highlight": { "pre_tags": "<b>", "post_tags": "</b>", "fields": { "location": {} } } }

原文地址:https://www.cnblogs.com/ch2020/p/15641722.html