Elasticsearch中的精确(不是子串)匹配 [英] Exact (not substring) matching in Elasticsearch

查看:135
本文介绍了Elasticsearch中的精确(不是子串)匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

{查询:{
match:{
content:2
}
}}
匹配所有的文档整个内容包含数字2,但是我希望内容完全是2,没有更多,不要少 - 根据Java的String.equals的精神想到我的要求。

{"query":{ "match" : { "content" : "2" } }} matches all the documents whole content contains the number 2, however I would like the content to be exactly 2, no more no less - think of my requirement in a spirit of Java's String.equals.

同样,对于第二个查询,我想在文档的内容完全为3 3时匹配,没有什么更多或更少。 {查询:{
match:{
content:3 3
}
}}

Similarly for the second query I would like to match when the document's content is exactly '3 3' and nothing more or less. {"query":{ "match" : { "content" : "3 3" } }}

如何在Elasticsearch中进行精确的(String.equals)匹配?

How could I do exact (String.equals) matching in Elasticsearch?

推荐答案

没有看到你的索引类型映射和样本数据,很难直接回答这个问题 - 但是我会尝试。

Without seeing your index type mapping and sample data, it's hard to answer this directly - but I'll try.

Offhand,我会说这个类似于这里的答案( https://stackoverflow.com/a/12867852/382774 ),您只需设置您的映射中内容字段的索引选项到 not_analyzed

Offhand, I'd say this is similar to this answer here (https://stackoverflow.com/a/12867852/382774), where you simply set the content field's index option to not_analyzed in your mapping:

"url" : {
    "type" : "string", 
    "index" : "not_analyzed"
}

编辑:我不清楚我的原始答案,显示以上。我并不意味着您应该将示例代码添加到您的查询,我的意思是您需要在索引类型映射中指定 url 字段的类型为 string ,它被编入索引但未分析( not_analyzed

I wasn't clear enough with my original answer, shown above. I did not mean to imply that you should add the example code to your query, I meant that you need to specify in your index type mapping that the url field is of type string and it is indexed but not analyzed (not_analyzed).

当您索引您的文档时,这告诉Elasticsearch不要分析(令牌化或令牌过滤)字段 - 只需将其存储在索引中即可文件。有关映射的更多信息,请参阅 http://www.elasticsearch.org/guide/reference/映射/ ,以及 http://www.elasticsearch .org / guide / reference / mapping / core-types / 有关 not_analyzed 的细节(提示:在该页面上搜索)。

This tells Elasticsearch to not bother analyzing (tokenizing or token filtering) the field when you're indexing your documents - just store it in the index as it exists in the document. For more information on mappings, see http://www.elasticsearch.org/guide/reference/mapping/ for an intro and http://www.elasticsearch.org/guide/reference/mapping/core-types/ for specifics on not_analyzed (tip: search for it on that page).

这篇关于Elasticsearch中的精确(不是子串)匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆