0

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"
        }
       }
     }
  ]
}
mikemaccana
  • 110,530
  • 99
  • 389
  • 494
aleha_84
  • 8,309
  • 2
  • 38
  • 46

2 Answers2

1

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

GET _search
{
  "query": {
    "term" : { "content.keyword" : "some search phraze" } 
  }
}
avr
  • 4,835
  • 1
  • 19
  • 30
0

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",
                     }
                 }
             }
         ]
    }
Community
  • 1
  • 1
aleha_84
  • 8,309
  • 2
  • 38
  • 46