3

I'm trying to add a complex filter on a wildcard query with elastic search. The filter seems to be working, however, the results don't talk into account the wildcard. Is this possible or is there an alternative to the wildcard filter? Query 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, can I add the wildcard as a filter inside my "bool": { "must": .... }} ?

user3241997
  • 165
  • 1
  • 8
  • 1
    I am triggered by your value is_animal false, since a frog is an animal. Any chance that could be your issue? Maybe replace wildcart query with a match_all query and check if you document is there. – Jettro Coenradie Jan 31 '15 at 11:59
  • Actually, a frog is a reptile :) – user3241997 Feb 03 '15 at 04:19
  • i tried using your approach and it gives me 0 hits http://stackoverflow.com/questions/35586116/elasticsearch-filter-does-not-work-with-wildcard-query – AbtPst Feb 23 '16 at 19:12
  • for me, its the filter that does not seem to be working! – AbtPst Feb 23 '16 at 19:13

1 Answers1

1

You should definitely use ngram token filter in your analyzer instead of running a wildcard which is really slow, especially if it starts with a star which is the case here.

That being said, I don't understand why the wildcard part is not applied here. Any chance you could reproduce your case with a full example? May be you have specific analyzer?

dadoonet
  • 14,109
  • 3
  • 42
  • 49