Elastic Search v6.3:使用过滤器查询从不 returns 任何匹配项
Elastic Search v6.3: Query with filter never returns any matches
我在使用 Elastic Search 时遇到了一些挑战。我想通过一些文本查询,然后根据类别进行过滤。我关注了 Elastic Search 6.3 Documentation for Queries 但我对 ES
的回复总是空的。我知道我至少有一个 应该 符合请求的条目。下面我将我的查询发布到 Elastic Search,我知道的条目出现在我的 Elastic Search 索引中。很感谢任何形式的帮助。
查询
{
"from": 0,
"size": 300,
"query": {
"bool": {
"filter": {
"term": {"category": "Soups"}
},
"should": [
{"term": {"instructions": "Matt"}},
{"term": {"introduction": "Matt"}},
{"term": {"recipe_name": "Matt"}},
],
"minimum_should_match": 1,
"boost": 1.0
}
}
}
Elastic Search 中存在记录
{
"_index": "recipes",
"_type": "_doc",
"_id": "QMCScWoBkkkjW61rD81v",
"_score": 0.2876821,
"_source": {
"calories": 124,
"category": "Soups",
"cook_time": {
"hour": "2",
"min": "4"
},
"cooking_temp": "375",
"cooking_temp_units": "°F",
"creator_username": "virtualprodigy",
"ingredients": [
{
"majorQuantity": "1 ",
"measuring_units": "teaspoon",
"minorQuantity": " ",
"name": "mett"
}
],
"instructions": "instructions",
"introduction": "intro",
"prep_time": {
"hour": "1",
"min": "2"
},
"recipe_name": "Matt Test",
"servings": 1
}
}
您的字段可能使用标准分析器编制了索引,这意味着它们被拆分为标记并小写。 term query is an exact match and does not perform this analysis, so you are looking for 'Matt' and it only has 'matt'. You look for 'Soups' and it only has 'soups'. The easiest fix is to change your term queries into match queries。例如:
{
"from": 0,
"size": 300,
"query": {
"bool": {
"filter": {
"match": {
"category": "Soups"
}
},
"should": [
{"match": {"instructions": "Matt"}},
{"match": {"introduction": "Matt"}},
{"match": {"recipe_name": "Matt"}}
],
"minimum_should_match": 1,
"boost": 1.0
}
}
}
我在使用 Elastic Search 时遇到了一些挑战。我想通过一些文本查询,然后根据类别进行过滤。我关注了 Elastic Search 6.3 Documentation for Queries 但我对 ES
的回复总是空的。我知道我至少有一个 应该 符合请求的条目。下面我将我的查询发布到 Elastic Search,我知道的条目出现在我的 Elastic Search 索引中。很感谢任何形式的帮助。
查询
{
"from": 0,
"size": 300,
"query": {
"bool": {
"filter": {
"term": {"category": "Soups"}
},
"should": [
{"term": {"instructions": "Matt"}},
{"term": {"introduction": "Matt"}},
{"term": {"recipe_name": "Matt"}},
],
"minimum_should_match": 1,
"boost": 1.0
}
}
}
Elastic Search 中存在记录
{
"_index": "recipes",
"_type": "_doc",
"_id": "QMCScWoBkkkjW61rD81v",
"_score": 0.2876821,
"_source": {
"calories": 124,
"category": "Soups",
"cook_time": {
"hour": "2",
"min": "4"
},
"cooking_temp": "375",
"cooking_temp_units": "°F",
"creator_username": "virtualprodigy",
"ingredients": [
{
"majorQuantity": "1 ",
"measuring_units": "teaspoon",
"minorQuantity": " ",
"name": "mett"
}
],
"instructions": "instructions",
"introduction": "intro",
"prep_time": {
"hour": "1",
"min": "2"
},
"recipe_name": "Matt Test",
"servings": 1
}
}
您的字段可能使用标准分析器编制了索引,这意味着它们被拆分为标记并小写。 term query is an exact match and does not perform this analysis, so you are looking for 'Matt' and it only has 'matt'. You look for 'Soups' and it only has 'soups'. The easiest fix is to change your term queries into match queries。例如:
{
"from": 0,
"size": 300,
"query": {
"bool": {
"filter": {
"match": {
"category": "Soups"
}
},
"should": [
{"match": {"instructions": "Matt"}},
{"match": {"introduction": "Matt"}},
{"match": {"recipe_name": "Matt"}}
],
"minimum_should_match": 1,
"boost": 1.0
}
}
}