[英]Term query does not return any results
I am trying to find some entities in Elastic search using nested term query. 我正在尝试使用嵌套术语查询在Elastic搜索中找到一些实体。 If I execute my search query there are no hits.
如果我执行搜索查询,则没有命中。 But if I change the query to use "match" instead of "term" I will have hits.
但是,如果我将查询更改为使用“匹配”而不是“术语”,那么我将获得点击。 What could I be doing wrong ?
我可能做错了什么?
What I am trying to achieve is to have only exact matches returned. 我试图实现的是仅返回完全匹配的内容。
Entity in ES is as follows ES中的实体如下
"vehiclesCollection": [
{
"id": "c0163692-69c5-442e-a30c-a3789384904d",
"additionalFields": {
"23698e0d-e5ba-4c0e-9c41-09db40708f09@11b75c17-1f62-4a45-847b- 348f3e6a5485@1a61281d-73b0-41ea-964d-d869a172752d": "HaveNoIdea",
"23698e0d-e5ba-4c0e-9c41-09db40708f09@11b75c17-1f62-4a45-847b-348f3e6a5485@91b5e07e-6e09-4a81-a3ef-d43f1ea99b34": "Strane",
"23698e0d-e5ba-4c0e-9c41-09db40708f09@11b75c17-1f62-4a45-847b-348f3e6a5485@4fc4d50b-5c81-47f7-8c7a-7802c28c0dca": true,
"23698e0d-e5ba-4c0e-9c41-09db40708f09@11b75c17-1f62-4a45-847b-348f3e6a5485@c35b1e06-f918-4f70-a323-804c004ddcbe": "License Plate"
},
"searchableAdditionalFieldValues": [
"License Plate",
"Strane",
"HaveNoIdea"
]
}
]
HINT: This is just the part I perform the search on. 提示:这只是我执行搜索的部分。
It has following mappings 它具有以下映射
{
"vehiclesCollection": {
"type": "nested",
"properties": {
"additionalFields": {
"properties": {
"23698e0d-e5ba-4c0e-9c41-09db40708f09@11b75c17-1f62-4a45-847b-348f3e6a5485@1a61281d-73b0-41ea-964d-d869a172752d": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"23698e0d-e5ba-4c0e-9c41-09db40708f09@11b75c17-1f62-4a45-847b-348f3e6a5485@4fc4d50b-5c81-47f7-8c7a-7802c28c0dca": {
"type": "boolean"
},
"23698e0d-e5ba-4c0e-9c41-09db40708f09@11b75c17-1f62-4a45-847b-348f3e6a5485@91b5e07e-6e09-4a81-a3ef-d43f1ea99b34": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"23698e0d-e5ba-4c0e-9c41-09db40708f09@11b75c17-1f62-4a45-847b-348f3e6a5485@c35b1e06-f918-4f70-a323-804c004ddcbe": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
},
"id": {
"type": "keyword"
},
"searchableAdditionalFieldValues": {
"type": "text",
"index_options": "offsets",
"analyzer": "ngram_tokenizer_analyzer",
"search_analyzer": "whitespace_analyzer"
}
}
}
}
And search query (in which if term is switched with match it will work, but I want only exact matches) 和搜索查询(如果将术语与匹配项切换会起作用,但我只希望完全匹配)
{
"bool": {
"must": [
{
"nested": {
"query": {
"term": {
"vehiclesCollection.additionalFields.23698e0d-e5ba-4c0e-9c41-09db40708f09@11b75c17-1f62-4a45-847b-348f3e6a5485@c35b1e06-f918-4f70-a323-804c004ddcbe": {
"value": "License Plate",
"boost": 1
}
}
},
"path": "vehiclesCollection",
"ignore_unmapped": false,
"score_mode": "avg",
"boost": 1
}
},
{
"nested": {
"query": {
"term": {
"vehiclesCollection.additionalFields.23698e0d-e5ba-4c0e-9c41-09db40708f09@11b75c17-1f62-4a45-847b-348f3e6a5485@1a61281d-73b0-41ea-964d-d869a172752d": {
"value": "HaveNoIdea",
"boost": 1
}
}
},
"path": "vehiclesCollection",
"ignore_unmapped": false,
"score_mode": "avg",
"boost": 1
}
},
{
"nested": {
"query": {
"term": {
"vehiclesCollection.additionalFields.23698e0d-e5ba-4c0e-9c41-09db40708f09@11b75c17-1f62-4a45-847b-348f3e6a5485@4fc4d50b-5c81-47f7-8c7a-7802c28c0dca": {
"value": true,
"boost": 1
}
}
},
"path": "vehiclesCollection",
"ignore_unmapped": false,
"score_mode": "avg",
"boost": 1
}
}
]
}
}
My first idea is that its related to the search analyses. 我的第一个想法是,它与搜索分析有关。 But I am not sure how to set them for this specific query.
但是我不确定如何为该特定查询设置它们。 I am using Elasticsearch Java API.
我正在使用Elasticsearch Java API。
The rule of thumb is that you need to 经验法则是您需要
term
queries on the .keyword
sub-fields .keyword
子字段上运行term
查询 text
top-level fields text
顶级字段上运行匹配查询 So your query would be (the first two nested term
queries are using the ***.keyword
sub-field): 因此您的查询将是(前两个嵌套
term
查询使用***.keyword
子字段):
{
"bool": {
"must": [
{
"nested": {
"query": {
"term": {
"vehiclesCollection.additionalFields.23698e0d-e5ba-4c0e-9c41-09db40708f09@11b75c17-1f62-4a45-847b-348f3e6a5485@c35b1e06-f918-4f70-a323-804c004ddcbe.keyword": {
"value": "License Plate",
"boost": 1
}
}
},
"path": "vehiclesCollection",
"ignore_unmapped": false,
"score_mode": "avg",
"boost": 1
}
},
{
"nested": {
"query": {
"term": {
"vehiclesCollection.additionalFields.23698e0d-e5ba-4c0e-9c41-09db40708f09@11b75c17-1f62-4a45-847b-348f3e6a5485@1a61281d-73b0-41ea-964d-d869a172752d.keyword": {
"value": "HaveNoIdea",
"boost": 1
}
}
},
"path": "vehiclesCollection",
"ignore_unmapped": false,
"score_mode": "avg",
"boost": 1
}
},
{
"nested": {
"query": {
"term": {
"vehiclesCollection.additionalFields.23698e0d-e5ba-4c0e-9c41-09db40708f09@11b75c17-1f62-4a45-847b-348f3e6a5485@4fc4d50b-5c81-47f7-8c7a-7802c28c0dca": {
"value": true,
"boost": 1
}
}
},
"path": "vehiclesCollection",
"ignore_unmapped": false,
"score_mode": "avg",
"boost": 1
}
}
]
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.