Retrieving nested objects using `SearchRequestBuilder`

(Arinto Murdopo) #1

Hi all,

Here's our sample document:

  .... we have other fields in this document
  "urlEntities": [
      "url": "https://x.xx/xxxxxxx",
      "expandedURL": "https://xxxxxxx.xxxx/p/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/",
      "end": 92,
      "start": 69,
      "displayURL": ""
  "createAtMilis": 1438757536000,
  "createdAt": "Aug 5, 2015 2:52:16 PM",
  .... we have other fields in this document

We tried to scan and filter the indices with many of those documents using this SearchRequestBuilder:

      SearchRequestBuilder srb = client.prepareSearch(index)
                .addFields("createdAt", "createAtMilis", "urlEntities")
                        FilterBuilders.rangeFilter( "createAtMilis").from(1398902400000L).to(1438757537000L),

However, we don't get any SearchHit.

If we change the addFields line to addFields("createdAt", "createAtMilis", "urlEntities.expandedUrl"), we are able to get valid SearchHit, but the SearchHit doesn't contain field urlEntities.expandedUrl.

Is it the expected behavior of addFields and search with Scan in Elasticsearch? We would like to limit the number of resulting fields and to not retrieve the whole _source field.

How can we handle this case?


(Arinto Murdopo) #2

Nevermind, apparently I use wrong field name. Problem solved! yay!

(system) #3