Elasticsearch bool must_not doesn't work with multi-fields. -


i use multi-fields https://www.elastic.co/guide/en/elasticsearch/reference/current/_multi_fields.html

here part of mapping:

... "diagnosis": {                "type": "string",                "fields":{                  "not_analyzed":{                     "type":"string",                     "index":"not_analyzed"                  }                 }             } ... 

i run query:

curl -xget 'elasticsearch_server:9200/db-index/diagnosis/_search?pretty' -d '{"query": {"bool": {"must_not": [{"match": {"diagnosis.not_analyzed": "f06.4 - organic anxiety disorder"}}], "must": [{"match": {"diagnosis": "dementia disease disorder"}}]}}}' 

despite must_not clause query above returns "f06.4 - organic anxiety disorder" string amid other results.

i can exclude results 'anxiety' word doing

curl -xget 'elasticsearch_server:9200/db-index/diagnosis/_search?pretty' -d '{"query": {"bool": {"must_not": [{"match": {"diagnosis": "anxiety"}}], "must": [{"match": {"diagnosis": "dementia disease disorder"}}]}}}' 

but goal exclude exact string "f06.4 - organic anxiety disorder" results. how can that?

try 1) change mapping lower case data don't cut them word (default mapping )

curl -xput 'localhost:9200/...../' -d '{  "settings":{      "index":{         "analysis":{            "analyzer":{               "keylower":{                  "tokenizer":"keyword",                  "filter":"lowercase"               }            }         }      }   },   "mappings":{         "specimens" : {             "_all" : {"enabled" : true},             "_index" : {"enabled" : true},             "_id" : {"index": "not_analyzed", "store" : false},             "properties" : {                  "diagnosis" : {"type" : "string",   "store" : "yes","index": "not_analyzed" }               }         }     } } 

2) return data not containing "organic anxiety disorder" (where * can words)

{     "query" : {         "bool" : {             "must_not" : [{                     "wildcard" : {                         "diagnosis" : {                             "value" : "*organic anxiety disorder*"                         }                     }                  }             ]         }     } }    

3) use strict search exclude data :

{     "query" : {         "bool" : {             "must_not" : [{                     "term" : {                         "diagnosis.not_analyzed" : "f06.4 - organic anxiety disorder"                     }                 }             ]         }     } }  

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -