Specifying fields in a search using the Java API results in no source being returned

Hi,

I am trying to search an index using the Java API, but only retrieve certain
fields from it. I think I have encountered a situation where if one tries to
specify any fields, using SearchRequestBuilder.addFields(), the source
always comes back empty. Here is a gist :

https://gist.github.com/905570#file_test_es.java

which should run with only elasticsearch in its classpath. Its output is
here :

https://gist.github.com/905570#file_output_java.txt

For comparison, running the same search on the command line :

https://gist.github.com/905570#file_search_on_command_line.sh

returns the correct results :

https://gist.github.com/905570#file_output_ommand_line.json

Best, Giles.

Thats the behavior (both in Java API and REST API), once you specify a field, then _source is not returned, and you have access to only those fields.
On Wednesday, April 6, 2011 at 3:45 PM, Giles Velarde wrote:

Hi,

I am trying to search an index using the Java API, but only retrieve certain fields from it. I think I have encountered a situation where if one tries to specify any fields, using SearchRequestBuilder.addFields(), the source always comes back empty. Here is a gist :

https://gist.github.com/905570#file_test_es.java

which should run with only elasticsearch in its classpath. Its output is here :

Retrieving selected _source fields from a search using Java API · GitHub

For comparison, running the same search on the command line :

Retrieving selected _source fields from a search using Java API · GitHub

returns the correct results :

Retrieving selected _source fields from a search using Java API · GitHub

Best, Giles.

That's taken me a long while to fathom. Thanks for clarifying this, Shay!

Best, Giles.

On 6 April 2011 14:36, Shay Banon shay.banon@elasticsearch.com wrote:

Thats the behavior (both in Java API and REST API), once you specify a
field, then _source is not returned, and you have access to only those
fields.

On Wednesday, April 6, 2011 at 3:45 PM, Giles Velarde wrote:

Hi,

I am trying to search an index using the Java API, but only retrieve
certain fields from it. I think I have encountered a situation where if one
tries to specify any fields, using SearchRequestBuilder.addFields(), the
source always comes back empty. Here is a gist :

https://gist.github.com/905570#file_test_es.java

which should run with only elasticsearch in its classpath. Its output is
here :

Retrieving selected _source fields from a search using Java API · GitHub

For comparison, running the same search on the command line :

Retrieving selected _source fields from a search using Java API · GitHub

returns the correct results :

Retrieving selected _source fields from a search using Java API · GitHub

Best, Giles.