8

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?

userab12345
  • 121
  • 1
  • 6

2 Answers2

4

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

userab12345
  • 121
  • 1
  • 6
0

Use Phrase matching like this :

{
"query": {
    "match_phrase": {
        "movie_name": "a"
    }
}
}
Master Mind
  • 3,014
  • 4
  • 32
  • 63
  • I tried this but this still gives back "mad max 3d". As the documentation says "but keeps only documents that contain all of the search terms" in my case both the terms are found in "mad max 3d". – userab12345 May 20 '15 at 23:17
  • is movie_name an analyzed field? because the fact the query must match upper and down case can be solved by analyzing the field – Master Mind May 20 '15 at 23:20
  • Do you apply in your analyzer a lowercase analyzer? – Master Mind May 20 '15 at 23:57