Elasticsearch:如何查询长字段以进行精确匹配
Elasticsearch: how to query a long field for exact match
我的文档具有以下映射属性:
"sid" : {"type" : "long", "store": "yes", "index": "no"},
此属性的每条记录只有一个值。我想查询此属性。我尝试了以下查询:
{
"query" : {
"term" : {
"sid" : 10
}
}
}
{
"query" : {
"match" : {
"sid" : 10
}
}
}
但是,我没有得到任何结果。我确实有一个 sid 等于 10 的文件。我做错了什么?我想查询此属性是否完全匹配。
感谢和问候。
index
: Set to analyzed
for the field to be indexed and searchable after being
broken down into token using an analyzer. not_analyzed
means that its
still searchable, but does not go through any analysis process or
broken down into tokens. no
means that it won’t be searchable at all
(as an individual field; it may still be included in _all
). Setting to
no
disables include_in_all
. Defaults to analyzed
.
因此,通过将 index
设置为 no
,您无法单独搜索该字段。因此,您需要从 index
中删除 no
并选择其他内容,或者您可以使用 "include_in_all":"yes"
并使用不同类型的查询:
"query": {
"match": {
"_all": 10
}
}
我的文档具有以下映射属性:
"sid" : {"type" : "long", "store": "yes", "index": "no"},
此属性的每条记录只有一个值。我想查询此属性。我尝试了以下查询:
{
"query" : {
"term" : {
"sid" : 10
}
}
}
{
"query" : {
"match" : {
"sid" : 10
}
}
}
但是,我没有得到任何结果。我确实有一个 sid 等于 10 的文件。我做错了什么?我想查询此属性是否完全匹配。
感谢和问候。
index
: Set toanalyzed
for the field to be indexed and searchable after being broken down into token using an analyzer.not_analyzed
means that its still searchable, but does not go through any analysis process or broken down into tokens.no
means that it won’t be searchable at all (as an individual field; it may still be included in_all
). Setting tono
disablesinclude_in_all
. Defaults toanalyzed
.
因此,通过将 index
设置为 no
,您无法单独搜索该字段。因此,您需要从 index
中删除 no
并选择其他内容,或者您可以使用 "include_in_all":"yes"
并使用不同类型的查询:
"query": {
"match": {
"_all": 10
}
}