I am new to Elasticsearch. I have the following query:
{
"query": {
"filtered" : {
"query" : {
"term" : {
"title" : "crime"
}
},
"filter" : {
"term" : { "year" : 1961 }
}
}
}
}
It runs fine under Windows prompt as follows:
curl -XGET localhost:9200/book/_search?pretty -d @my-query.json
For the same query with Java client, I have the following:
SearchResponse sr = client.prepareSearch("book")
.setTypes("fiction")
.setQuery(query_string)
.setFrom(page)
.setSize(10).execute().actionGet();
However, I have to the following query string in order to run it without exception:
{
"filtered" : {
"query" : {
"term" : {
"title" : "crime"
}
},
"filter" : {
"term" : { "year" : 1961 }
}
}
}
Why is there such a difference? How can I retain the removed "query" property"? Suppose that I have to use query string in my Java client.
Thanks and regards!