aleha_84
aleha_84

Reputation: 8539

Elastic search phrase exact match without analysing

Current elastic mapping:

"properties": {
"content": {
    "type": "text",
       "term_vector":"with_positions_offsets",
     "fields": {
         "keyword": {                
             "type": "keyword",
             "ignore_above": 256
         }
    },
     "analyzer": "russian"
   }        
}

Field "content" contains results of site crawling, exactly pages "body" tag content, stripped off from tags. Task is to realize three types of search for this field. 1. All specified words 2. Any of the specified words 3. Exactly in the text

For 1 case - match_phrase For 2 case - match For 3 case - there must be match_phrase without analizing, becouse with "russian" analizer it finds this phraze with different endings and declensions

Tried this query with no luck:

"query": {
"bool": {
    "must": [
     {
      "match_phrase": {   
           "content":  {
               "query": "some search phraze",
       "analyzer": "keyword"
        }
       }
     }
  ]
}

Upvotes: 0

Views: 882

Answers (2)

aleha_84
aleha_84

Reputation: 8539

Self answering

This answer helped me a lot

Adding extra field "raw" to property solved problem.

"properties": {
    "content": {
        "type": "text",
        "term_vector":"with_positions_offsets",
        "fields": {
            "keyword": {
                "type": "keyword",
                "ignore_above": 256
            },
            "raw": {
                "type": "text",
                "index": "analyzed"
            }
        },
    "analyzer": "russian"
    }        
}  

search query looks like this:

"query": {
    "bool": {
        "must": [
             {
                 "match_phrase": {   
                     "content.raw":  {
                          "query": "some search phraze",
                     }
                 }
             }
         ]
    }

Upvotes: 0

avr
avr

Reputation: 4883

For exact match query use Term Query. So your query should look like below:

GET _search
{
  "query": {
    "term" : { "content.keyword" : "some search phraze" } 
  }
}

Upvotes: 1

Related Questions