# How can I get fields from SearchResponse?

**URL:** <https://discuss.elastic.co/t/how-can-i-get-fields-from-searchresponse/157622>\
**Category:** Elasticsearch\
**Created:** [November 21, 2018, 4:27am UTC](https://discuss.elastic.co/t/how-can-i-get-fields-from-searchresponse/157622 "2018-11-21T04:27:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![byeong\_seok\_park](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/byeong_seok_park/32/48056_2.png) [@byeong\_seok\_park](https://discuss.elastic.co/u/byeong_seok_park)\
**Post date:** [November 21, 2018, 4:27am UTC](https://discuss.elastic.co/t/how-can-i-get-fields-from-searchresponse/157622/1 "2018-11-21T04:27:02Z")

</div>

I just wonder how I get fields from SearchResponse which is result of my query.

Below is my query:

```
{"size":99,"timeout":"10s","query":{"bool":{"filter":[{"bool":{"must":[{"range":{"LOG_GEN_TIME":{"from":"2018-11-01 12:00:01+09:00","to":"2018-11-01 23:59:59+09:00","include_lower":true,"include_upper":true,"boost":1.0}}},{"wrapper":{"query":"eyAiYmvbCIgOiB7ICN0IiA6IFsgeyAidIgOiB7ICJBFVF9JUCIgOiAiMTAuMTExLjI1Mi4xNiIgfSB9LCB7ICJ0ZsgIkFDVElPTl9UWVBFX0NEIiA6ICgInRlcm0iIDogeyAiRFUlQiIDogIjggXSB9IH="}}],"adjust_pure_negative":true,"boost":1.0}}],"adjust_pure_negative":true,"boost":1.0}},"_source":{"includes":["LOG_GEN_TIME","LOG_NO","ASSET_NO"],"excludes":[]},"sort":[{"LOG_GEN_TIME":{"order":"desc"}},{"LOG_NO":{"order":"desc"}}]}

```

and when I query this, like below:

```
SearchRequestBuilder request = client.prepareSearch("indexName");
SearchResponse searchResponse = request.get();

```

I got right result:

```
{  
   "took":1071,
   "timed_out":false,
   "_shards":{  
      "total":14,
      "successful":14,
      "skipped":0,
      "failed":0
   },
   "_clusters":{  
      "total":0,
      "successful":0,
      "skipped":0
   },
   "hits":{  
      "total":2,
      "max_score":null,
      "hits":[  
         {  
            "_index":"log_20181101",
            "_type":"SEC",
            "_id":"1197132746951492963",
            "_score":null,
            "_source":{  
               "ASSET_NO":1,
               "LOG_NO":1197132746951492963,
               "LOG_GEN_TIME":"2018-11-01 09:46:28+09:00"
            },
            "sort":[  
               1541033188000,
               1197132746951492963
            ]
         },
         {  
            "_index":"log_20181101",
            "_type":"SEC",
            "_id":"1197132746951492963",
            "_score":null,
            "_source":{  
               "ASSET_NO":2,
               "LOG_NO":1197337264704454700,
               "LOG_GEN_TIME":"2018-11-01 23:00:06+09:00"
            },
            "sort":[  
               1541080806000,
               1197337264704454700
            ]
         }
      ]
   }
}

```

To use this result, I need to map this by field and value.

![cap](https://us1.discourse-cdn.com/elastic/original/3X/a/f/af3535b282215618a56ec98307b0cbe38bf4c2fd.png)

I think there's a way to map the field and value to the 'fields' parameter so that we could use it nicely, but I cannot find.

I hope I can use the result like this way:

```
SearchHit hit = ...
Map<String, SearchHitField> fields = hit.getFields();
String logNo = fields.get("LOG_NO").value();

```

And It seems like this is the common way to use..

Or am I misunderstanding something? Tell me other way if there's better way, please.

Any comment would be appreciated. Thanks.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 19, 2018, 4:27am UTC](https://discuss.elastic.co/t/how-can-i-get-fields-from-searchresponse/157622/2 "2018-12-19T04:27:04Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
