This not a query. A query has to start with query type and follow Query DSLhttp://www.elasticsearch.org/guide/reference/query-dsl/index.html.
You can make a query out of it by making this json a part of match query
for example:
{
"match_phrase": {
description:"Cisco Network Data Switch"
}
}
But it will not be very flexible solution in the long run. I would advise
parsing this json in your application and building an appropriate query out
of it.
On Wednesday, January 16, 2013 12:06:59 AM UTC-5, JD wrote:
Hi,
I have a search string that is already JSON string like this:
{
description:"Cisco Network Data Switch"
}
When I pass it to the code below :
SearchRequestBuilder srb =
client.prepareSearch("asset_index").setTypes("Asset").setSearchType(
SearchType.DEFAULT).setQuery(search);
SearchResponse response = srb.execute().actionGet();
... I get :
org.elasticsearch.action.search.SearchPhaseExecutionException: Failed to
execute phase [query], total failure; shardFailures
{[PdwFM8JUTjqVbZqPEdOT0w][asset_index][0]:
SearchParseException[[asset_index][0]: from[-1],size[-1]: Parse Failure
[Failed to parse source
[{"query_binary":"ewoJZGVzY3JpcHRpb246IkNpc2NvIE5ldHdvcmsgRGF0YSBTd2l0Y2giCn0="}]]];
nested: QueryParsingException[[asset_index] [_na] query malformed, no field
after start_object]; }{[PdwFM8JUTjqVbZqPEdOT0w][asset_index][4]:
SearchParseException[[asset_index][4]: from[-1],size[-1]: Parse Failure
[Failed to parse source
[{"query_binary":"ewoJZGVzY3JpcHRpb246IkNpc2NvIE5ldHdvcmsgRGF0YSBTd2l0Y2giCn0="}]]];
nested: QueryParsingException[[asset_index] [_na] query malformed, no field
after start_object]; }{[PdwFM8JUTjqVbZqPEdOT0w][asset_index][1]:
SearchParseException[[asset_index][1]: from[-1],size[-1]: Parse Failure
[Failed to parse source
[{"query_binary":"ewoJZGVzY3JpcHRpb246IkNpc2NvIE5ldHdvcmsgRGF0YSBTd2l0Y2giCn0="}]]];
nested: QueryParsingException[[asset_index] [_na] query malformed, no field
after start_object]; }{[PdwFM8JUTjqVbZqPEdOT0w][asset_index][3]:
SearchParseException[[asset_index][3]: from[-1],size[-1]: Parse Failure
[Failed to parse source
[{"query_binary":"ewoJZGVzY3JpcHRpb246IkNpc2NvIE5ldHdvcmsgRGF0YSBTd2l0Y2giCn0="}]]];
nested: QueryParsingException[[asset_index] [_na] query malformed, no field
after start_object]; }Regards,
Janusz
--