Build Query based on Json using Java client


(None) #1

I have some written Json queries and I would like to execute them using the Java client.

The below requires me to break the json in individual parts and pass it in as arguments.

client.prepareSearch(index).setTypes(type).setSearchType(SearchType.DEFAULT).setQuery(query).addSort("myfield", SortOrder.ASC).setScroll(new TimeValue(60000)).setSize(10000).execute().actionGet()

for Instance setQuery() only takes the query portion, then addSort fields 1 by 1, same for fields.

Can we simply read a Json document from file into a String and pass the whole thing through.


(Jason Wee) #2

you can use wrapperQuery https://github.com/elastic/elasticsearch/blob/master/core/src/test/java/org/elasticsearch/search/query/SearchQueryTests.java#L834-L847

hth


(system) #3