[英]Elastic search term filter is not working
This is my elastic search query for fetching the id 这是我用于获取ID的弹性搜索查询
curl -XGET localhost:9200/test-index2/business/_search -d'
{
"query" : {
"filtered" : {
"query" : {
"match_all" : {}
},
"filter" : {
"term" : {
"_id" : "AU6LqK0WCSY7HKQGengx"
}
}
}
}
}'
And this is part of the response 这是回应的一部分
{"contactNumber": "+1-415-392-3702", "name": "Golden Gate Hotel"}
I've got the contactNumber and name 我有contactNumber和名称
Now my second query -> i'm querying for the above contact number using term filter 现在我的第二个查询->我正在使用术语过滤器查询上述联系电话
curl -XGET localhost:9200/test-index2/business/_search -d'
{
"query" : {
"filtered" : {
"query" : {
"match_all" : {}
},
"filter" : {
"term" : {
"contactNumber" : "+1-415-392-3702"
}
}
}
}
}'
and i've got 0 hits! 而且我有0次点击!
I've indexed both the contactNumber and name field. 我已经索引了contactNumber和name字段。
What am i doing wrong?? 我究竟做错了什么??
I should be getting the exact same record back 我应该得到完全相同的记录
Edit: 编辑:
Attaching the mapping for contact number 附加联系人号码的映射
{"test-index2":{"mappings":{"business":{"properties":{"address":{"type":"string"},"contactNumber":{"type":"string","store":true},"name":{"type":"string"}}}}}}
term
filter doesn't analyze the input text, meaning if you search for "+1-415-392-3702" then this is the exact text it's expecting to find in the index. term
过滤器不会分析输入文本,这意味着如果您搜索“ + 1-415-392-3702”,则这是它期望在索引中找到的确切文本。
But, your field being just the default string
this means it most probably uses the standard
analyzer for analyzing it. 但是,您的字段只是默认string
这意味着它很可能使用standard
分析器对其进行分析。 This means that in the index you'll have these tokens: "1","3702","392","415"
and not a single +1-415-392-3702
. 这意味着在索引中,您将拥有以下标记: "1","3702","392","415"
而不是单个+1-415-392-3702
。
So, you need either one of these two: 因此,您需要以下两个之一:
"contactNumber": {
"type": "string",
"index": "not_analyzed",
"store":true
}
or 要么
"contactNumber": {
"type": "string",
"analyzer": "keyword",
"store":true
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.