A simple AND query with Elasticsearch

后端 未结 3 2040
执笔经年
执笔经年 2021-02-07 06:17

I am trying to do a simple query for two specified fields, and the manual and google is proving to be of little help. Example below should make it pretty clear what I want to do

3条回答
  •  孤街浪徒
    2021-02-07 06:42

    I found a solution for at least multiple text comparisons on the same field:

    {
      "query": {
        "match": {
          "name.given_name": {
            "query": "daniel tyrone",
            "operator": "and"
          }
        }
      }
    

    And I found this for multiple fields, is this the correct way?

    {
      "query": {
        "bool": {
          "must": [        
            {
              "match": {
                "name.formatted": {
                  "query": "daniel tyrone",
                  "operator": "and"
                }
              }
            },
            {
              "match": {
                "display_name": "tyrone"
              }
            }
          ]
        }
      }
    }
    

提交回复
热议问题