【发布时间】:2016-06-16 13:08:05
【问题描述】:
考虑以下两个查询:
{
"_source" : false,
"query": {
"bool": {
"must": [
{
"range": {
"date": {
"gte": 1460789348000,
"lte": 1466059748000
}
}
}
]
}
}
}
现在考虑添加了filtered 和filter 字段的以下查询:
{
"_source": false,
"query": {
"filtered": {
"filter": {
"bool": {
"must": [
{
"range": {
"date": {
"gte": 1460789348000,
"lte": 1466059748000
}
}
}
]
}
}
}
}
}
两者都给出相同的结果,并且没有 filtered 和 filter 字段的第一个查询不会导致错误,这与以下查询不同:
{
"_source": false,
"query": {
"bool": {
"must": [
{
"exists": {
"field": "comment"
}
}
]
}
}
}
错误:
{
"error": "SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[bi8BrruxR9i_H8-n4Qo9Mg][acct_prop_5][0]: RemoteTransportException[[Battletide][inet[/172.16.0.11:9302]][indices:data/read/search[phase/query]]]; nested: SearchParseException[[acct_prop_5][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"_source":false,"query":{"bool":{"must":[{"exists":{"field":"comment"}}]}}}]]]; nested: QueryParsingException[[acct_prop_5] No query registered for [exists]]; }{[JorHtifCSxGrbb3ovGJMWQ][advocacy_insights_p5_v1_00000000_0000][0]: RemoteTransportException[[Caiera][inet[/172.16.0.11:9304]][indices:data/read/search[phase/query]]]; nested: SearchParseException[[advocacy_insights_p5_v1_00000000_0000][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"_source":false,"query":{"bool":{"must":[{"exists":{"field":"comment"}}]}}}]]]; nested: QueryParsingException[[advocacy_insights_p5_v1_00000000_0000] No query registered for [exists]]; }{[Tlt3tXF_S9-rEmK9iwSvoA][audience_act_p5_v2_00000000_0000][0]: RemoteTransportException[[Monet St. Croix][inet[/172.16.0.11:9303]][indices:data/read/search[phase/query]]]; nested: SearchParseException[[audience_act_p5_v2_00000000_0000][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"_source":false,"query":{"bool":{"must":[{"exists":{"field":"comment"}}]}}}]]]; nested: QueryParsingException[[audience_act_p5_v2_00000000_0000] No query registered for [exists]]; }{[NTpZwKeYRI6l6zHf2BlIFg][audience_act_p5_v3_00000000_0000][0]: SearchParseException[[audience_act_p5_v3_00000000_0000][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"_source":false,"query":{"bool":{"must":[{"exists":{"field":"comment"}}]}}}]]]; nested: QueryParsingException[[audience_act_p5_v3_00000000_0000] No query registered for [exists]]; }{[NTpZwKeYRI6l6zHf2BlIFg][audience_act_p5_v3_20150601_0000][0]: SearchParseException[[audience_act_p5_v3_20150601_0000][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"_source":false,"query":{"bool":{"must":[{"exists":{"field":"comment"}}]}}}]]]; nested: QueryParsingException[[audience_act_p5_v3_20150601_0000] No query registered for [exists]]; }{[Tlt3tXF_S9-rEmK9iwSvoA][auth2][0]: RemoteTransportException[[Monet St. Croix][inet[/172.16.0.11:9303]][indices:data/read/search[phase/query]]]; nested: SearchParseException[[auth2][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"_source":false,"query":{"bool":{"must":[{"exists":{"field":"comment"}}]}}}]]]; nested: QueryParsingException[[auth2] No query registered for [exists]]; }{[JorHtifCSxGrbb3ovGJMWQ][authors][0]: RemoteTransportException[[Caiera][inet[/172.16.0.11:9304]][indices:data/read/search[phase/query]]]; nested: SearchParseException[[authors][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"_source":false,"query":{"bool":{"must":[{"exists":{"field":"comment"}}]}}}]]]; nested: QueryParsingException[[authors] No query registered for [exists]]; }{[bi8BrruxR9i_H8-n4Qo9Mg][bm_content_lifetime_p5_v1_00000000_0000][0]: RemoteTransportException[[Battletide][inet[/172.16.0.11:9302]][indices:data/read/search[phase/query]]]; nested: SearchParseException[[bm_content_lifetime_p5_v1_00000000_0000][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"_source":false,"query":{"bool":{"must":[{"exists":{"field":"comment"}}]}}}]]]; nested: QueryParsingException[[bm_content_lifetime_p5_v1_00000000_0000] No query registered for [exists]]; }{[NTpZwKeYRI6l6zHf2BlIFg][bm_content_lifetime_p5_v2_00000000_0000][0]: SearchParseException[[bm_content_lifetime_p5_v2_00000000_0000][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"_source":false,"query":{"bool":{"must":[{"exists":{"field":"comment"}}]}}}]]]; nested: QueryParsingException[[bm_content_lifetime_p5_v2_00000000_0000] No query registered for [exists]]; }{[bi8BrruxR9i_H8-n4Qo9Mg][bm_content_lifetime_p5_v93_00000000_0000][0]: RemoteTransportException[[Battletide][inet[/172.16.0.11:9302]][indices:data/read/search[phase/query]]]; nested: SearchParseException[[bm_content_lifetime_p5_v93_00000000_0000][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"_source":false,"query":{"bool":{"must":[{"exists":{"field":"comment"}}]}}}]]]; nested: .........
而有了这两个字段,它就变成了一个正确的查询:
{
"_source": false,
"query": {
"filtered": {
"filter": {
"bool": {
"must": [
{
"exists": {
"field": "comment"
}
}
]
}
}
}
}
}
range 和 exists 查询之间有什么区别?没有filtered 和filter 字段,只允许一个查询有效?
【问题讨论】:
-
您的所有查询都运行良好,对我来说没有任何错误。请添加您在执行查询时收到的错误消息,以便更清楚地了解。
标签: elasticsearch filter querydsl