ElasticSearch前缀查询的结果仅返回与查询匹配的文档。有没有办法可以将查询配置为还为每个导致匹配的文档返回“完全匹配”?
答案 0 :(得分:2)
好吧,使用Highlighting,您可以获得突出显示匹配单词的文字。即:
GET /_search
{
"query": {
"prefix": { "DESCRIPTION": "arthu"}
},
"highlight": {
"fields" : {
"DESCRIPTION" : {}
}
}
}
检索如下内容:
{
"_index": "abc",
"_type": "xyz",
"_id": "107507",
"_score": 1,
"_source": {
"DESCRIPTION": "Arthur: Attack of the Turbo Tibbles/D.W. Tricks the Tooth Fairy"
},
"highlight": {
"DESCRIPTION": [
"<em>Arthur</em>: Attack of the Turbo Tibbles/D.W. Tricks the Tooth Fairy"
]
}
}
您还可以自定义包装标签(em)。但我不确定如何从那里只提取匹配的单词。
无论如何看看这个帖子。我不了解实施情况,但可能有所帮助:Determining which words were matched in a fuzzy search
基本上他建议这样做:
GET /common_clarovideo/grupo/_search
{
"_source": [
"NOMBRE_INTERNO"
],
"query": {
"prefix": { "NOMBRE_INTERNO": "arthu"}
},
"highlight": {
"fields" : {
"NOMBRE_INTERNO" : {"fragment_size" : 5}
}
}
}
含义&#34; fragment_size&#34;必须与期限的长度相匹配。希望这会有所帮助。
答案 1 :(得分:1)
是的。您需要使用术语代替匹配,您将得到确切的术语。 见documentation