我使用多字段fields.html
下面是我映射的一部分:
...
"Diagnosis": {
"type": "string",
"fields":{
"not_analyzed":{
"type":"string",
"index":"not_analyzed"
}
}
}
...
我运行以下查询:
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"}}]}}}'
尽管有must_not子句,上述查询在其他结果中返回"F06.4 -有机焦虑症“字符串。
我可以用“焦虑”这个词来排除所有的结果
curl -XGET 'elasticsearch_server:9200/db-index/Diagnosis/_search?pretty' -d '{"query": {"bool": {"must_not": [{"match": {"Diagnosis": "anxiety"}}], "must": [{"match": {"Diagnosis": "Dementia disease disorder"}}]}}}'
但目标是从结果中只排除确切的字符串"F06.4 -有机焦虑症“。我怎么能这么做?
发布于 2016-02-08 12:52:26
尝试这样做:( 1)将映射更改为小写,但不要用word (默认映射)来剪切它们。
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)这将只返回不包含“有机焦虑症”(其中*
可以是任何单词)的数据。
{
"query" : {
"bool" : {
"must_not" : [{
"wildcard" : {
"Diagnosis" : {
"value" : "*organic anxiety disorder*"
}
}
}
]
}
}
}
3)使用严格搜索排除数据:
{
"query" : {
"bool" : {
"must_not" : [{
"term" : {
"Diagnosis.not_analyzed" : "f06.4 - organic anxiety disorder"
}
}
]
}
}
}
发布于 2016-02-08 12:21:17
如果要排除确切的字符串,请使用term query
like。
curl -XGET 'elasticsearch_server:9200/db-index/Diagnosis/_search? pretty' -d '{"query": {"bool": {"must_not": [{"term": {"Diagnosis.not_analyzed": "F06.4 - Organic anxiety disorder"}}], "must": [{"match": {"Diagnosis": "Dementia disease disorder"}}]}}}'
希望这能有所帮助
https://stackoverflow.com/questions/35268891
复制相似问题