搜索结果正在快递途中

ES5.2.2精准匹配附代码,求解答

Elasticsearch | 作者 Lincoln | 发布于2017年03月16日 | 阅读数:3837

ik分词,现搜索“高血压”返加“高血压”、“妊娠期高血压疾病”,怎么才能实现只返回“高血压”。另外已经把“妊娠期高血压疾病”已经维护进自定义字典。代码如下
##发送请求
curl -XGET 'http://10.20.112.229:9200/temp/_search?q=var02:"\"高血压\""&pretty'

##返回数据
{
"took" : 14,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 2,
"max_score" : 5.050649,
"hits" : [
{
"_index" : "temp",
"_type" : "disease_smart",
"_id" : "AVrQvAnX2otwkbs8jq9n",
"_score" : 5.050649,
"_source" : {
"var01" : "心内科",
"var02" : "高血压"
}
},
{
"_index" : "temp",
"_type" : "disease_smart",
"_id" : "AVrQvBC1cuw09-Q-5VmH",
"_score" : 3.2579603,
"_source" : {
"var01" : "妇产科",
"var02" : "妊娠期高血压疾病"
}
}
]
}
}

curl -XGET 'http://10.20.112.229:9200/temp/_search?q=var02:"\"妊娠期高血压疾病\""&pretty'
{
"took" : 17,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 9.357949,
"hits" : [
{
"_index" : "temp",
"_type" : "disease_smart",
"_id" : "AVrQvBC1cuw09-Q-5VmH",
"_score" : 9.357949,
"_source" : {
"var01" : "妇产科",
"var02" : "妊娠期高血压疾病"
}
}
]
}
}
已邀请:

Wumpus - 90后程序猿

赞同来自:

1、先分析字段存储情况
{
   "query" : {
      "term" : {
         "var02" : "高血压"
      }
   },
   "script_fields" : {
      "terms" : {
         "script" : "doc[field].values",
         "params" : {
            "field" : "var02"
         }
      }
   }
}
2、你会发现妊娠期高血压疾病也是存在高血压字段,因此你输入高血压也是能匹配得到。
解决方法:
1、存储时不分词,not_analyzer,只有这样才能在查询时候不分析

要回复问题请先登录注册