1

I did read this post but didn't quite understand how to apply it.

I have my index analyzed and I wanted to know if I can search for phrases without inflectional forms.

es.indices.create(index='bhar',body = {
 "settings":{
  "analysis":{
   "analyzer":{
    "my_stop_analyzer":{
     "type":"custom",
     "tokenizer":"standard",
     "filter":        ["english_possessive_stemmer","lowercase","english_stop","english_stemmer"]
              }
             },"filter":{
               "english_stop":{
                    "type":"stop",
                    "stopwords":"_english_"
                               },
                                 "english_stemmer":{
                                   "type":"stemmer",
                                   "name":"english"
                                    },
                                 "english_possessive_stemmer": {
                                   "type": "stemmer",
                                   "language": "possessive_english"
                                    }}}},
                          "mappings":{
                            "my_type":{
                               "properties":{
                                  "test": {
                                    "type":"text",
                                    "analyzer" : "my_stop_analyzer"
                                     }
                                     }
                                     }
                                     }
                                     })

`

And one record has data that is " picks towering". When I search for "pick tower", it still gives me a result with match_phrase which I wrote like this:

scroll = elasticsearch.helpers.scan(es, query={
    "query":{
    "match_phrase":{ 
    "test":{
    "query":"pick rule"
          }
                 }
          }
 },index='bhar', scroll='100s')`

Is there any way I can get only the exact match of the phrase? Thank you

Community
  • 1
  • 1
sleepophile
  • 659
  • 1
  • 7
  • 19

1 Answers1

1

Your analyzer is changing the terms that are indexed and there is no way for it to keep the original text. My suggestion is to change your mapping slightly:

    "test": {
      "type": "text",
      "analyzer": "my_stop_analyzer",
      "fields": {
        "keyword": {
          "type": "keyword"
        }
      }
    }

And introduce in your queries, also, the "exact matching" option:

"match_phrase": {
  "test.keyword": "picks towering"
}

or

  "query": {
    "bool": {
      "should": [
        {
          "match_phrase": {
            "test.keyword": "picks towering"
          }
        },
        {
          "match_phrase": {
            "test": "picks towering"
          }
        }
      ]
    }
  }

The second type of query above is meant not to interfere with whatever other queries you already have in there.

Andrei Stefan
  • 51,654
  • 6
  • 98
  • 89