弹性搜索中查询字符串和术语的组合

时间:2017-12-15 12:34:44

标签: elasticsearch

我有这个问题:

query: {
query: {
query_string: {
query: "Perspolis OR Branco",
default_field: "body"
}
},
from: 1,
size: 1
}

如何将此查询与对已处理字段的精确检查相结合:true和年龄介于10和20之间?

1 个答案:

答案 0 :(得分:0)

{
  "query": {
    "bool": {
      "must": [
        {
          "query_string": {
            "query": "Perspolis OR Branco",
            "default_field": "body"
          }
        },
        {
          "term": {
            "processed": {
              "value": true
            }
          }
        },
        {
          "range": {
            "age": {
              "gte": 10,
              "lte": 20
            }
          }
        }
      ]
    }
  },
  "from": 1,
  "size": 1
}