8
votes

I am new to ES. I am having trouble finding exact phrase matches.

Let's assume my index has a field called movie_name. Let's assume I have 3 documents with the following values

  1. movie_name = Mad Max
  2. movie_name = mad max
  3. movie_name = mad max 3d

If my search query is Mad Max, I want the first 2 documents to be returned but not the 3rd.

If I do the "not_analyzed" solution I will get only document 1 but not 2.

What am I missing?

2

2 Answers

4
votes

I was able to do it using the following commands, basically create a custom analyzer, use the keyword tokenizer to prevent tokenization. Then use the analyzer in the "mappings" for the desired field, in this case "movie_name".


        PUT /movie
        {
      "settings":{
         "index":{
            "analysis":{
               "analyzer":{
                  "keylower":{
                     "tokenizer":"keyword",
                     "filter":"lowercase"
                  }
               }
            }
         }
      },
        "mappings" : {
            "search" : {
                "properties" : {
                    "movie_name" : { "type" : "string", "analyzer":"keylower" }
                }
            }
        }
    }

0
votes

Use Phrase matching like this :

{
"query": {
    "match_phrase": {
        "movie_name": "a"
    }
}
}