Specifying Fields to Return in Source

Hi,

I thought to limit the fields I return in the source, I would do the
following:

SearchRequestBuilder searchReq = client.prepareSearch()
.addFields(DEFAULT_FIELDS)
.setIndices(indexes)
.setTypes(types)
.setQuery(queryBuilder)
.setFrom(this.start)
.setSize(pageSize);

Where default fields is something like this:

String[] DEFAULT_FIELDS = new String[]{"id","fullName","person_name"};

But, when I execute this query I find this:

     for (SearchHit hit : queryResponse.getHits()){
		Map<String, Object> source = hit.getSource();
     }

In this case the source object is set to null. Should I be using the
hit.fields() method instead?

Best Regards,

David.

Yes.

On Tuesday, June 14, 2011 at 12:57 PM, davrob2 wrote:

Hi,

I thought to limit the fields I return in the source, I would do the
following:

SearchRequestBuilder searchReq = client.prepareSearch()
.addFields(DEFAULT_FIELDS)
.setIndices(indexes)
.setTypes(types)
.setQuery(queryBuilder)
.setFrom(this.start)
.setSize(pageSize);

Where default fields is something like this:

String DEFAULT_FIELDS = new String{"id","fullName","person_name"};

But, when I execute this query I find this:

for (SearchHit hit : queryResponse.getHits()){
Map<String, Object> source = hit.getSource();
}

In this case the source object is set to null. Should I be using the
hit.fields() method instead?

Best Regards,

David.