Filter search by template in Elastic Search

I am trying to add a sophisticated lookup filter using elastic search. The filter seems to work, however the results do not take into account the wildcard. Is this possible or is there an alternative to the substitution filter? The request is as follows:

{
  "query": {
    "filtered": {
      "query": {
        "wildcard": {
          "name": "*frog*"
        },
        "filter": {
          "bool": {
            "must": {
              "term": {
                "is_animal": false
              }
            }
          },
          "or": [
            {
              "terms": {
                "reptiles.codes": [
                  27
                ]
              }
            },
            {
              "nested": {
                "path": "owners",
                "query": {
                  "bool": {
                    "should": {
                      "term": {
                        "pets": "cat"
                      }
                    }
                  }
                }
              }
            },
            {
              "nested": {
                "path": "locations",
                "query": {
                  "bool": {
                    "should": {
                      "term": {
                        "home": true
                      }
                    }
                  }
                }
              }
            }
          ]
        }
      }
    }
  }
}

Alternatively, you can add a wildcard as a filter inside my "bool": {"must": ....}}?

+4
source share
1 answer

You should definitely use the ngram token filter in your analyzer instead of starting a wildcard that is very slow, especially if it starts with the star that takes place here.

, , . , ? , ?

+1

All Articles