Specifying Fields to Return in Source

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Specifying Fields to Return in Source

davrob
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.
Reply | Threaded
Open this post in threaded view
|

Re: Specifying Fields to Return in Source

kimchy
Administrator
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.