Elasticsearch multi term filter

前端 未结 2 1790
伪装坚强ぢ
伪装坚强ぢ 2021-01-30 08:57

I\'m quite new to Elasticsearch, so here\'s my question. I wanna do a search query with elasticsearch and wanna filter with multiple terms.

If I want to search for a use

2条回答
  •  误落风尘
    2021-01-30 09:08

    As one of the comments says, the syntax has changed in recent ES versions. If you are using Elasticsearch 6.+, and you want to use a wildcard and a sequence of terms in your query (such as in the question), you can use something like this:

    GET your_index/_search
    {
      "query": {
        "bool": {
          "must": [
            {
              "wildcard": {
                "your_field_name_1": {
                  "value": "tom*"
                }
              }
            },
            {
              "term": {
                "your_field_name_2": {
                  "value": "US"
                }
              }
            },
            {
              "term": {
                "your_field_name_3": {
                  "value": "Michigan"
                }
              }
            },
            {
              "term": {
                "your_field_name_4": {
                  "value": "0"
                }
              }
            }
          ]
        }
      }
    }
    

    Also, from the documentation about wildcard queries:

    Note that this query can be slow, as it needs to iterate over many terms. In order to prevent extremely slow wildcard queries, a wildcard term should not start with one of the wildcards * or ?.

    I hope this helps.

提交回复
热议问题