我正在尝试对我的ElasticSearch Server执行此查询。
{
"query" : {
"match" : {
"name" : "network"
}
},
"facets" : {
"departments" : {
"terms" : {
"field" : "department_name"
}
}
},
"filter" : {
"bool": {
"should": [
{ "match" : {"department_name" : "book"}},
{ "match" : {"department_name" : "electronics"}}]
}
}
}
基本上,我希望检索名称中与“网络”匹配的所有产品,但仅过滤department_name
与book
或electronics
匹配的产品。当我执行此查询时,收到此错误消息。
curl -X POST "http://localhost:9200/products/_search?pretty=true" -d '{
"query" : {
"match" : {
"name" : "network"
}
},
"facets" : {
"departments" : {
"terms" : {
"field" : "department_name"
}
}
},
"filter" : {
"bool": {
"should": [
{ "match" : {"department_name" : "book"}},
{ "match" : {"department_name" : "electronics"}}]
}
}
}
'
{
"error" : "SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[EaNRci0OSIqpA2EAPwAA6w][products][4]: SearchParseException[[products][4]: query[name:network],from[-1],size[-1]: Parse Failure [Failed to parse source [{\n \"query\" : {\n \"match\" : {\n \"name\" : \"network\"\n }\n },\n \"facets\" : {\n \"departments\" : { \n \"terms\" : {\n \"field\" : \"department_name\"\n } \n }\n },\n\n \"filter\" : {\n \"bool\": {\n \"should\": [\n { \"match\" : {\"department_name\" : \"book\"}},\n { \"match\" : {\"department_name\" : \"electronics\"}}] \n } \n }\n}\n]]]; nested: QueryParsingException[[products] No filter registered for [match]]; }{[EaNRci0OSIqpA2EAPwAA6w][products][0]: SearchParseException[[products][0]: query[name:network],from[-1],size[-1]: Parse Failure [Failed to parse source [{\n \"query\" : {\n \"match\" : {\n \"name\" : \"network\"\n }\n },\n \"facets\" : {\n \"departments\" : { \n \"terms\" : {\n \"field\" : \"department_name\"\n } \n }\n },\n\n \"filter\" : {\n \"bool\": {\n \"should\": [\n { \"match\" : {\"department_name\" : \"book\"}},\n { \"match\" : {\"department_name\" : \"electronics\"}}] \n } \n }\n}\n]]]; nested: QueryParsingException[[products] No filter registered for [match]]; }{[EaNRci0OSIqpA2EAPwAA6w][products][1]: SearchParseException[[products][1]: query[name:network],from[-1],size[-1]: Parse Failure [Failed to parse source [{\n \"query\" : {\n \"match\" : {\n \"name\" : \"network\"\n }\n },\n \"facets\" : {\n \"departments\" : { \n \"terms\" : {\n \"field\" : \"department_name\"\n } \n }\n },\n\n \"filter\" : {\n \"bool\": {\n \"should\": [\n { \"match\" : {\"department_name\" : \"book\"}},\n { \"match\" : {\"department_name\" : \"electronics\"}}] \n } \n }\n}\n]]]; nested: QueryParsingException[[products] No filter registered for [match]]; }{[EaNRci0OSIqpA2EAPwAA6w][products][2]: SearchParseException[[products][2]: query[name:network],from[-1],size[-1]: Parse Failure [Failed to parse source [{\n \"query\" : {\n \"match\" : {\n \"name\" : \"network\"\n }\n },\n \"facets\" : {\n \"departments\" : { \n \"terms\" : {\n \"field\" : \"department_name\"\n } \n }\n },\n\n \"filter\" : {\n \"bool\": {\n \"should\": [\n { \"match\" : {\"department_name\" : \"book\"}},\n { \"match\" : {\"department_name\" : \"electronics\"}}] \n } \n }\n}\n]]]; nested: QueryParsingException[[products] No filter registered for [match]]; }{[EaNRci0OSIqpA2EAPwAA6w][products][3]: SearchParseException[[products][3]: query[name:network],from[-1],size[-1]: Parse Failure [Failed to parse source [{\n \"query\" : {\n \"match\" : {\n \"name\" : \"network\"\n }\n },\n \"facets\" : {\n \"departments\" : { \n \"terms\" : {\n \"field\" : \"department_name\"\n } \n }\n },\n\n \"filter\" : {\n \"bool\": {\n \"should\": [\n { \"match\" : {\"department_name\" : \"book\"}},\n { \"match\" : {\"department_name\" : \"electronics\"}}] \n } \n }\n}\n]]]; nested: QueryParsingException[[products] No filter registered for [match]]; }]",
"status" : 400
}
我认为这里的关键是QueryParsingException[[products] No filter registered for [match]]
,但是无法理解这里的错误。
答案 0 :(得分:9)
match
是一个查询,而不是过滤器。
在这种情况下,您可能需要term
- 过滤器。
答案 1 :(得分:9)
{
"query": {
"filtered": {
"query": { //THIS IS THE MAIN SEARCH BLOCK FOR ALL RESULTS
"match": {
"title": {
"query": "[MAIN_SEARCH_TERM]",
"minimum_should_match": "75%"
}
}
},
"filter": {
"bool": {
"must": [
{
"range": { //THIS FILTERS BY DATES GRATER THAN [SOME_DATE]
"date": {
"gte":"[SOME DATE]"
}
}
},
{
"geo_distance": { //THIS FILTERS BY GEO POINTS WITHIN [DISTANCE] of [LATITUDE], [LONGITUDE]
"distance": "[DISTANCE](mi, km)",
"location": {
"lat":"[LATITUDE]",
"lon":"[LONGITUDE]"
}
}
}
],
"should": [
{
"query": { //THIS FILTERS BY ANOTHER [MATCH_TERM] AND ADDS BOOST TO THAT TERM, YOU CAN USE MULTIPLE OF THESE WITH DIFFERENT [BOOST_INT]
"match": {
"[PROPERTY]": {
"query": "[MATCH_TERM]",
"boost": [BOOST_INT]
}
}
}
}
]
}
}
}
}
}
参考链接:http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/query-time-boosting.html
在使用geo_point匹配和日期范围过滤之前,请确保您了解_mapping: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping.html
答案 2 :(得分:0)
对于遇到过这种将主要版本迁移到弹性搜索5的人来说,此过滤后的查询现在已经过折旧,您应该使用bool查询。 https://discuss.elastic.co/t/no-query-registered-for-filter/49602