Elasticsearch精确匹配词组 [英] Elasticsearch exact match pharse
问题描述
我想在Elasticsearch中搜索一个词组以查找完全匹配.但是Elasticsearch也给出了其他包含的词组.
一个例子;我想搜索小猫",但Elasticsearch返回小猫跳",小猫",小猫救死了婴儿"等.
我只想要确切的,只有小猫",而不是其他.我该如何查询?
我的内容喜欢;
{标题:小猫",内容:"bla bla bla"},...
这很大程度上取决于 title
的索引方式.对于此类要求,标题
必须为分析为 keyword
,这意味着 title
中的任何文本都与ES内部Lucene倒排索引中的文本完全一样.
并且 term
过滤器将是搜索以 keyword
分析的 title
中的 little cat
的选择./p>
如果您希望在编制索引时对 title
字段进行其他操作,则可以将其设置为 multi_field
,并添加一个 title_keyword
(例如)字段,该字段应使用您的关键字
分析器.
I want to search a pharse in Elasticsearch for exact match. But Elasticsearch giving other containing pharses too.
An example; I want to search for "little cat", but Elasticsearch returns "little cat jump", "little cats", "little cat saved the baby from death", etc...
I just want exact and only "little cat", not the others. How can I do this query?
My contents like;
{
title: "little cat",
content: "bla bla bla"
},
...
It depends a lot on how title
is indexed. For such a requirement, title
would need to be analyzed as keyword
, meaning whatever text is in title
exactly like that is put in ES' internal Lucene inverted index.
And a term
filter would be the choice for searching little cat
in title
analyzed as keyword
.
If you want to have other operations made to your title
field at indexing time, you can add a filter, for example for lowercasing any upper-case letters. But, in any case, you DO need a keyword
analyzer.
If you don't want to change how title
is being indexed now, you can make it as multi_field
and add a title_keyword
(for example) field that should be indexed using your keyword
analyzer.
这篇关于Elasticsearch精确匹配词组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!