kyle k
kyle k

Reputation: 5512

Elasticsearch find missing word in phrase

How can i use Elasticsearch to find the missing word in a phrase? For example i want to find all documents which contain this pattern make * great again, i tried using a wildcard query but it returned no results:

   {
  "fields": [
    "file_name",
    "mime_type",
    "id",
    "sha1",
    "added_at",
    "content.title",
    "content.keywords",
    "content.author"
  ],
  "highlight": {
    "encoder": "html",
    "fields": {
      "content.content": {
        "number_of_fragments": 5
      }
    },
    "order": "score",
    "tags_schema": "styled"
  },
  "query": {
    "wildcard": {
      "content.content": "make * great again"
    }
  }
}

If i put in a word and use a match_phrase query i get results, so i know i have data which matches the pattern.

Which type of query should i use? or do i need to add some type of custom analyzer to the field?

Upvotes: 0

Views: 332

Answers (1)

David Ostrovsky
David Ostrovsky

Reputation: 2481

Wildcard queries operate on terms, so if you use it on an analyzed field, it will actually try to match every term in that field separately. In your case, you can create a not_analyzed sub-field (such as content.content.raw) and run the wildcard query on that. Or just map the actual field to not be analyzed, if you don't need to query it in other ways.

Upvotes: 1

Related Questions