1
votes

I am newbie to ELasticsearch and would need your help regarding ES returning unmatched results for analyzed field. i have a custom analyzer as follows:

 "analyzer": {
            "testing_analyzer": {
               "type": "custom",
               "char_filter": "html_strip",
               "tokenizer": "standard",
               "filter": [
                  "lowercase",
                  "asciifolding",
                  "snowball",
                  "stop"
               ]
            },
            "testing_search_analyzer": {
               "type": "custom",
               "char_filter": "html_strip",
               "tokenizer": "standard",
               "filter": [
                  "lowercase",
                  "asciifolding"
               ]
            }
         }

i have set this analyzer for a field on both index & search as follows.

"name":
{
"type": "string",
"analyzer": "testing_analyzer",
"search_analyzer": "testing_search_analyzer"
}

but when search for name "università di bologna", it return first result record have same match, but some other records not match (2nd record in result below):

Record1:

 [ "Università di Bologna", "University of Bologna", "CNR", "Università di Pisa", "University of Pisa", "Mineraria e Delle Tecnologie Ambientali" ]

Record2:

[ "University of Salerno", "Università di Salerno" ]

Query :

 {
   "fields": [
      "doc_id",
      "name"
   ],
   "query": {
      "match": {
         "name": "Università di bologna"
      }
   }
}

any help ?!

1
how is testing_search_analyzer defined ?keety
"testing_search_analyzer": { "type": "custom", "char_filter": "html_strip" , "tokenizer": "standard", "filter": [ "lowercase", "asciifolding"] },Telebh
can you show the query too ?keety
curl -XGET 'localhost:9200/users/_search?pretty=true' -d ' { "fields" : ["doc_id" , "name"], "query": { "match": { "name": "Università di bologna" } } }'Telebh

1 Answers

1
votes

The results are as expected. By default the match query does an 'OR' of the tokens generated by tokenizer.

Try changing the query to following:

{
   "fields": [
      "doc_id",
      "name"
   ],
   "query": {
      "match": {
         "name": {
            "query": "Università di bologna",
            "operator": "and"
         }
      }
   }
}