Hello,

I am using the Java API and loading a complex JSON formatted query from a 
text file and using setSource() of the SearchRequestBuilder
to prepare the search.  What I like to do now is programmatically overwrite 
or change values loaded form source using the Java API, i.e.

json query source:
{
...
"sort" : [
    "_score"
  ],
....
}

SearchRequestBuilder search = 
client.prepareSearch("indexname").setSource(json.toString());
search.addSort(SortBuilders.fieldSort("somefield").order(SortOrder.ASC);

I would expect an effective query like:

{
...
"sort" : [
    "_score",
    { "somefield" : "asc"}
  ],
....
}

However, it does not seem to work this way. Debugging the request object 
yields something like:

------
indexname!:)
 �sort��somefield�orderBasc���� {
...
"sort" : [
    "_score"
  ],
....
-------

Which I would interpret as that the programmatically set values for "sort" 
being overwritten by the setSource JSON following after. 
I have since found that setting the field "sort" programmatically only 
works as I expect it if the JSON source does not contain it at all.

I've tried to use setExtraSource instead of setSource without success.

Is it even possible what I am trying to accomplish here? Or do I need to 
find another approach (like using templates, or building the full query 
programmatically?)


Thanks
Andreas





-- 
You received this message because you are subscribed to the Google Groups 
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elasticsearch/6a6d683b-ac50-4abe-9141-af60f7a810c4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to