繁体   English   中英

Elasticsearch 多字段查询

[英]Elasticsearch multiple fields query

我请求你的帮助。 elasticsearch 先创建搜索查询,搜索字段为关键字类型

数据

"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"
            }
          ]
        }
      }
}

搜索时,必须是keyword=developer and search=or

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

但是,'keyword=developer and search=and'也是一种搜索。 我该如何编写查询?

使用下面的查询

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM