Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

elastic search exact phrase matching

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?

like image 728
userab12345 Avatar asked May 20 '15 22:05

userab12345


People also ask

How do you search exact words in Elasticsearch?

If you want to match the whole string "Classe A" and distinguish this from "Classe B", you can use the Keyword Analyzer. This will keep the entire field as one string. Then you can use the match query which will return the results you expect. Save this answer.

What is match phrase in Elasticsearch?

Match phrase queryedit A phrase query matches terms up to a configurable slop (which defaults to 0) in any order. Transposed terms have a slop of 2. The analyzer can be set to control which analyzer will perform the analysis process on the text.

What is the difference between match and match phrase in Elasticsearch?

Match phrase query is similar to the match query but is used to query text phrases. Phrase matching is necessary when the ordering of the words is important. Only the documents that contain the words in the same order as the search input are matched.

Should minimum should match?

Minimum Should Match is another search technique that allows you to conduct a more controlled search on related or co-occurring topics by specifying the number of search terms or phrases in the query that should occur within the records returned.


1 Answers

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" }
                }
            }
        }
    }

like image 122
userab12345 Avatar answered Sep 30 '22 08:09

userab12345