Reputation: 15002
I got this Exception , it seems show me there are exception in the query statements.
However, I could figure out what should I modify, any idea?
(pry) output error: #<Elasticsearch::Transport::Transport::Errors::BadRequest: [400] {"error":{"root_cause":[{"type":"query_parsing_exception","reason":"[_na] query malformed, no field after start_object","index":"flights","line":1,"col":11}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"flights","node":"mVtcYMIfRxOBeqWvMbShhA","reason":{"type":"query_parsing_exception","reason":"[_na] query malformed, no field after start_object","index":"flights","line":1,"col":11}}]},"status":400}>
{
"size": 0,
"query": {
"filtered": {
"query": {
"query_string": {
"analyze_wildcard": true,
"query": "total_price_twd: [10 TO 10000]"
}
},
"filter": {
"bool": {
"must": [
{
"range": {
"departure_at": {
"gte": 1452164239142,
"lte": 1457348239142,
"format": "epoch_millis"
}
}
}
],
"must_not": []
}
}
}
},
"aggs": {
"3": {
"date_histogram": {
"field": "departure_at",
"interval": "1d",
"time_zone": "Asia/Shanghai",
"min_doc_count": 1,
"extended_bounds": {
"min": 1452164239141,
"max": 1457348239141
}
}
}
}
}
Q_PARAMS = {
"size":0,
"query":{
"filtered":{
"query":{
"query_string":{
"analyze_wildcard":true,
"query":"total_price_twd: [10 TO 10000]"
}
},
"filter":{
"bool":{
"must":[
{
"range":{
"departure_at":{
"gte":1452164239142,
"lte":1457348239142,
"format":"epoch_millis"
}
}
}
],
"must_not":[
]
}
}
}
},
"aggs":{
"3":{
"date_histogram":{
"field":"departure_at",
"interval":"1d",
"time_zone":"Asia/Shanghai",
"min_doc_count":1,
"extended_bounds":{
"min":1452164239141,
"max":1457348239141
}
}
}
}
}
def self.es_search
__elasticsearch__.search(
{
query: Q_PARAMS,
size: 200
}
)
end
{
"took": 23,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 12991,
"max_score": 0,
"hits": []
},
"aggregations": {
"3": {
"buckets": [
{
"key_as_string": "2016-01-07T00:00:00.000+08:00",
"key": 1452096000000,
"doc_count": 46
},
...
]
}
}
}
elasticsearch_1 | [2016-03-07 11:05:04,273][INFO ][rest.suppressed ] //flights/flight/_search Params: {index=flights, type=flight}
elasticsearch_1 | Failed to execute phase [query], all shards failed; shardFailures {[mVtcYMIfRxOBeqWvMbShhA][flights][0]: RemoteTransportException[[Payback][172.17.0.3:9300][indices:data/read/search[phase/query]]]; nested: SearchParseException[failed to parse search source [{"query":{"size":0,"query":{"filtered":{"query":{"query_string":{"analyze_wildcard":true,"query":"total_price_twd: [10 TO 10000]"}},"filter":{"bool":{"must":[{"range":{"departure_at":{"gte":1452164239142,"lte":1457348239142,"format":"epoch_millis"}}}],"must_not":[]}}}},"aggs":{"3":{"date_histogram":{"field":"departure_at","interval":"1d","time_zone":"Asia/Shanghai","min_doc_count":1,"extended_bounds":{"min":1452164239141,"max":1457348239141}}}}},"size":200}]]; nested: QueryParsingException[[_na] query malformed, no field after start_object]; }{[mVtcYMIfRxOBeqWvMbShhA][flights][1]: RemoteTransportException[[Payback][172.17.0.3:9300][indices:data/read/search[phase/query]]]; nested: SearchParseException[failed to parse search source [{"query":{"size":0,"query":{"filtered":{"query":{"query_string":{"analyze_wildcard":true,"query":"total_price_twd: [10 TO 10000]"}},"filter":{"bool":{"must":[{"range":{"departure_at":{"gte":1452164239142,"lte":1457348239142,"format":"epoch_millis"}}}],"must_not":[]}}}},"aggs":{"3":{"date_histogram":{"field":"departure_at","interval":"1d","time_zone":"Asia/Shanghai","min_doc_count":1,"extended_bounds":{"min":1452164239141,"max":1457348239141}}}}},"size":200}]]; nested: QueryParsingException[[_na] query malformed, no field after start_object]; }{[mVtcYMIfRxOBeqWvMbShhA][flights][2]: RemoteTransportException[[Payback][172.17.0.3:9300][indices:data/read/search[phase/query]]]; nested: SearchParseException[failed to parse search source [{"query":{"size":0,"query":{"filtered":{"query":{"query_string":{"analyze_wildcard":true,"query":"total_price_twd: [10 TO 10000]"}},"filter":{"bool":{"must":[{"range":{"departure_at":{"gte":1452164239142,"lte":1457348239142,"format":"epoch_millis"}}}],"must_not":[]}}}},"aggs":{"3":{"date_histogram":{"field":"departure_at","interval":"1d","time_zone":"Asia/Shanghai","min_doc_count":1,"extended_bounds":{"min":1452164239141,"max":1457348239141}}}}},"size":200}]]; nested: QueryParsingException[[_na] query malformed, no field after start_object]; }{[mVtcYMIfRxOBeqWvMbShhA][flights][3]: RemoteTransportException[[Payback][172.17.0.3:9300][indices:data/read/search[phase/query]]]; nested: SearchParseException[failed to parse search source [{"query":{"size":0,"query":{"filtered":{"query":{"query_string":{"analyze_wildcard":true,"query":"total_price_twd: [10 TO 10000]"}},"filter":{"bool":{"must":[{"range":{"departure_at":{"gte":1452164239142,"lte":1457348239142,"format":"epoch_millis"}}}],"must_not":[]}}}},"aggs":{"3":{"date_histogram":{"field":"departure_at","interval":"1d","time_zone":"Asia/Shanghai","min_doc_count":1,"extended_bounds":{"min":1452164239141,"max":1457348239141}}}}},"size":200}]]; nested: QueryParsingException[[_na] query malformed, no field after start_object]; }{[mVtcYMIfRxOBeqWvMbShhA][flights][4]: RemoteTransportException[[Payback][172.17.0.3:9300][indices:data/read/search[phase/query]]]; nested: SearchParseException[failed to parse search source [{"query":{"size":0,"query":{"filtered":{"query":{"query_string":{"analyze_wildcard":true,"query":"total_price_twd: [10 TO 10000]"}},"filter":{"bool":{"must":[{"range":{"departure_at":{"gte":1452164239142,"lte":1457348239142,"format":"epoch_millis"}}}],"must_not":[]}}}},"aggs":{"3":{"date_histogram":{"field":"departure_at","interval":"1d","time_zone":"Asia/Shanghai","min_doc_count":1,"extended_bounds":{"min":1452164239141,"max":1457348239141}}}}},"size":200}]]; nested: QueryParsingException[[_na] query malformed, no field after start_object]; }
elasticsearch_1 | at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.onFirstPhaseResult(TransportSearchTypeAction.java:228)
Upvotes: 1
Views: 700
Reputation: 33626
Try wrapping it in a body
key and executing it straight from the Client
object:
Q_PARAMS = {
size: 200,
query: {
filtered: {
query: {
query_string: {
analyze_wildcard: true,
query: "total_price_twd: [10 TO 10000]"
}
},
filter: {
bool: {
must: [
{
"range":{
"departure_at":{
"gte":1452164239142,
"lte":1457348239142,
"format":"epoch_millis"
}
}
}
],
"must_not":[
]
}
}
}
},
"aggs":{
"3":{
"date_histogram":{
"field":"departure_at",
"interval":"1d",
"time_zone":"Asia/Shanghai",
"min_doc_count":1,
"extended_bounds":{
"min":1452164239141,
"max":1457348239141
}
}
}
}
}
def self.es_search
__elasticsearch__.client.search(body: Q_PARAMS)
end
Upvotes: 4