{"query":{
"match" : {
"content" : "2"
}
}} 匹配所有文档的整个内容包含数字2,但是我希望内容完全是2,不多也不少 - 以Java的String.equals的精神来考虑我的要求.
类似地,对于第二个查询,我想匹配文档的内容正好是'3 3'并且没有更多或更少. {"query":{
"match" : {
"content" : "3 3"
}
}}
我怎样才能在Elasticsearch中进行精确(String.equals)匹配?
如果没有看到您的索引类型映射和示例数据,很难直接回答这个问题 - 但我会尝试。
顺便说一句,我想说这与这里的答案类似(/sf/answers/900749671/),您只需在映射中将content字段的index选项设置为:not_analyzed
"url" : {
"type" : "string",
"index" : "not_analyzed"
}
Run Code Online (Sandbox Code Playgroud)
编辑:我的原始答案不够清楚,如上所示。我并不是暗示您应该将示例代码添加到您的查询中,我的意思是您需要在索引类型映射中指定该url字段的类型string,并且它已被索引但未分析(not_analyzed)。
这告诉 Elasticsearch 在为文档建立索引时不必费心分析(标记化或标记过滤)字段 - 只需将其存储在索引中,就像文档中存在的那样。有关映射的更多信息,请参阅http://www.elasticsearch.org/guide/reference/mapping/了解简介,并参阅http://www.elasticsearch.org/guide/reference/mapping/core-types/了解详细信息not_analyzed(提示:在该页面上搜索)。
更新:
官方文档告诉我们,在新版本的 Elastic search 中,您不能将变量定义为“not_analyzed”,而应该使用“keyword”。
对于旧版本的松紧带:
{
"foo": {
"type" "string",
"index": "not_analyzed"
}
Run Code Online (Sandbox Code Playgroud)
}
对于新版本:
{
"foo": {
"type" "keyword",
"index": true
}
}
Run Code Online (Sandbox Code Playgroud)
请注意,此功能(关键字类型)来自 elastic 5.0,向后兼容层已从 Elasticsearch 6.0 版本中删除。
| 归档时间: |
|
| 查看次数: |
8517 次 |
| 最近记录: |