elasticsearch 弹性多字段查询

js5cn81o  于 2022-11-28  发布在  ElasticSearch
关注(0)|答案(1)|浏览(149)

我在请求你的帮助。
搜索字段为关键字类型
数据库

"hits" : [
      {
        "_index" : "search_event",
        "_type" : "_doc",
        "_score" : 5.179434,
        "_source" : {
          "search_keyword" : [
            {
              "search" : "or",
              "keyword" : "developer",
              "type" : "18"
            }
       ]
    },
    {
        "_source" : {
          "search_keyword" : [
            {
              "search" : "or",
              "keyword" : "tail"
            },
            {
              "search" : "or",
              "keyword" : "cap"
            },
            {
              "search" : "and",
              "keyword" : "developer"
            }
          ]
        }
      }
}

搜索时,必须是关键字=developer且搜索=或但关键字=developer且搜索=,并且被搜索

"query": {
    "bool": {
      "filter": [
        {
          "term": {
            "search_keyword.keyword": {
              "value": "developer"
            }
          }
        },
        {
          "term": {
            "search_keyword.search": {
              "value": "or"
            }
          }
        }
      ]
    }
  }
}

不过,'关键字=开发者和搜索=和'也不过是一个搜索。
如何编写查询?

dgsult0t

dgsult0t1#

使用以下查询

"query": {
    "bool": {
      "must": [ --> note instead of `filter`, it's `must` clause.
        {
          "term": {
            "search_keyword.keyword": {
              "value": "developer"
            }
          }
        },
        {
          "term": {
            "search_keyword.search": {
              "value": "or"
            }
          }
        }
      ]
    }
  }
}

相关问题