I have a query in standard JSON format that works pretty fine when queried directly from command line. The json is:
{"fields" : ["id"],
"query":{
"bool":{
"must":[
{
"custom_score" : {
"query" : {
"bool" : {
"should" : [
{
"term" : {"a.in.group" : "abcd"}
},
{
"term" : {"a.in.group": "ALL"}
}
]
}
},
"boost" : 1.0,
"script" : "_score"
}
},
{
"custom_score" : {
"query" : {
"bool" : {
"should" : [
{
"term" : {"b.in.prefix" : pre}
},
{
"term" : {"b.in.group" : "abc"}
}
]
}
},
"boost" : 1.0,
"script" : "_score"
}
}
]
}
}
}
This is giving me result as desired:
curl -X GET "localhost:9200/test/rule/_search" -d @query.json
{"took":6,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":1,"max_score":2.3251607,"hits":[{"_index":"memphis","_type":"rule","_id":"1","_score":2.3251607,"fields":{"id":1}}]}}
But I am unable to find the right syntex for the equivalent tire query. I tried:
s=Tire.search('test/rule') do
query do
boolean do
must [
query do
boolean do
should { string "a.in.group:abcd" }
should { string "a.in.group:ALL" }
end
end
query do
boolean do
should { string "b.in.prefix:pre" }
should { string "b.in.group:abc" }
end
end
]
end
end
fields :id
end
But this is giving me syntax error:
ruby -c query.rb
query.rb:7: syntax error, unexpected keyword_do_block, expecting ']'
query.rb:19: syntax error, unexpected ']', expecting keyword_end
query.rb:46: syntax error, unexpected $end, expecting keyword_end
I couldn’t find any help on any other forum. Problem occurs when I try to put multiple queries in the must block. Please help.
Thanks in Advance
-Azitabh
See if this will do the trick: