So it appears that ES wants its json hashes (for search, at least) to be in
a certain order. I was getting certain weird failures where it would
sometimes work and sometimes get the SearchPhaseExecutionException error.
This fails:
$ curl
http://localhost:9200/discussions_test_68/discussion/_search?routing=68 -d
'{"query":{"filtered":{
>
"filter":{"and":{"must":[{"term":{"site_id":68}}]},"or":[{"term":{"public":"1"}},{"term":{"watchers":171}}]},
>
"query":{"bool":{"must":[{"text":{"_all":{"operator":"and","query":"testing
2"}}}]}}
> }}}'
{"error":"SearchPhaseExecutionException[Failed to execute phase
[query_fetch], total failure; shardFailures
{[ogrJqB3SRM67cXPUZxx8rA][discussions_test][0]:
SearchParseException[[discussions_test][0]: from[-1],size[-1]: Parse
Failure [Failed to parse source [{"query":{"filtered":{
\n"filter":{"and":{"must":[{"term":{"site_id":68}}]},"or":[{"term":{"public":"1"}},{"term":{"watchers":171}}]},\n"query":{"bool":{"must":[{"text":{"_all":{"operator":"and","query":"testing
2"}}}]}}\n}}}]]]; nested: QueryParsingException[[discussions_test]
[filtered] requires 'query' element]; }]","status":500}
But then if we reverse the order of "filter" and "query" in
query[filtered], so that 'query' comes first --->
$ curl
http://localhost:9200/discussions_test_68/discussion/_search?routing=68 -d
'{"query":{"filtered":{
>
"query":{"bool":{"must":[{"text":{"_all":{"operator":"and","query":"testing
2"}}}]}},
>
"filter":{"and":{"must":[{"term":{"site_id":68}}]},"or":[{"term":{"public":"1"}},{"term":{"watchers":171}}]}
> }}}'
{"took":1,"timed_out":false,"_shards":{"total":1,"successful":1,"failed":0},"hits":{"total":0,"max_score":null,"hits":[]}}
Um, what? Am I crazy/stupid, or do you actually have to send the hash
values in a certain order for ES to accept them? FWIW the ruby library I am
using (ruby in general..) doesn't guarantee any particular ordering of
hash keys when serializing into JSON.
--Courtenay
--