# SearchHit Java API

**URL:** <https://discuss.elastic.co/t/searchhit-java-api/13518>\
**Category:** Elasticsearch\
**Created:** [September 9, 2013, 2:49pm UTC](https://discuss.elastic.co/t/searchhit-java-api/13518 "2013-09-09T14:49:08Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adrian\_2](https://avatars.discourse-cdn.com/v4/letter/a/c57346/32.png) [@Adrian\_2](https://discuss.elastic.co/u/Adrian_2)\
**Post date:** [September 9, 2013, 2:49pm UTC](https://discuss.elastic.co/t/searchhit-java-api/13518/1 "2013-09-09T14:49:08Z")

</div>

Hi,

I've seen that the SearchHit interface does not provide a method for accessing  
a field using the common java naming conventions. Would it be possible to add  
such a method with the name "getField"?

Thanks, Adrian

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [September 9, 2013, 2:52pm UTC](https://discuss.elastic.co/t/searchhit-java-api/13518/2 "2013-09-09T14:52:52Z")

</div>

It's not really a getter right?

SearchHit#field(String fieldName);

I assume that's probably the reason it was not modified to support getter/setter standard format.

Do you have any issue related to this?

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr | @scrutmydocs

Le 9 sept. 2013 à 16:49, Adrian [google@core.kyubu.de](mailto:google@core.kyubu.de) a écrit :

> Hi,
> 
> I've seen that the SearchHit interface does not provide a method for accessing  
> a field using the common java naming conventions. Would it be possible to add  
> such a method with the name "getField"?
> 
> Thanks, Adrian
> 
> --  
> You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Adrian\_2](https://avatars.discourse-cdn.com/v4/letter/a/c57346/32.png) [@Adrian\_2](https://discuss.elastic.co/u/Adrian_2)\
**Post date:** [September 9, 2013, 3:06pm UTC](https://discuss.elastic.co/t/searchhit-java-api/13518/3 "2013-09-09T15:06:33Z")

</div>

On Mon, Sep 09, 2013 at 04:52:52PM +0200, David Pilato wrote:

David,

> It's not really a getter right?  
> SearchHit#field(String fieldName);  
> I assume that's probably the reason it was not modified to support getter/setter standard format.  
> Do you have any issue related to this?

If you are using things like StringTemplate for accessing the objects, absence  
of the getters makes it difficult to fetch the values.

Best, Adrian

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [September 9, 2013, 3:10pm UTC](https://discuss.elastic.co/t/searchhit-java-api/13518/4 "2013-09-09T15:10:05Z")

</div>

In that case, what parameter do you send in fieldName?

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr | @scrutmydocs

Le 9 sept. 2013 à 17:06, Adrian [google@core.kyubu.de](mailto:google@core.kyubu.de) a écrit :

> On Mon, Sep 09, 2013 at 04:52:52PM +0200, David Pilato wrote:
> 
> David,
> 
> > It's not really a getter right?  
> > SearchHit#field(String fieldName);  
> > I assume that's probably the reason it was not modified to support getter/setter standard format.  
> > Do you have any issue related to this?
> 
> If you are using things like StringTemplate for accessing the objects, absence  
> of the getters makes it difficult to fetch the values.
> 
> Best, Adrian
> 
> --  
> You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Adrian\_2](https://avatars.discourse-cdn.com/v4/letter/a/c57346/32.png) [@Adrian\_2](https://discuss.elastic.co/u/Adrian_2)\
**Post date:** [September 9, 2013, 3:14pm UTC](https://discuss.elastic.co/t/searchhit-java-api/13518/5 "2013-09-09T15:14:55Z")

</div>

On Mon, Sep 09, 2013 at 05:10:05PM +0200, David Pilato wrote:

David,

> In that case, what parameter do you send in fieldName?

The field name which is contained (as key) in the map from getFields.

Best, Adrian

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [September 9, 2013, 3:27pm UTC](https://discuss.elastic.co/t/searchhit-java-api/13518/6 "2013-09-09T15:27:06Z")

</div>

Sorry. I don't get it.  
As you have the full map with getFields(), why not simply iterate other it? Or ask the map to give you the field you want?

Could you share with a Gist some code? It could help me to have a better picture here. I'm probably missing something.

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr | @scrutmydocs

Le 9 sept. 2013 à 17:14, Adrian [google@core.kyubu.de](mailto:google@core.kyubu.de) a écrit :

> On Mon, Sep 09, 2013 at 05:10:05PM +0200, David Pilato wrote:
> 
> David,
> 
> > In that case, what parameter do you send in fieldName?
> 
> The field name which is contained (as key) in the map from getFields.
> 
> Best, Adrian
> 
> --  
> You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Adrian\_2](https://avatars.discourse-cdn.com/v4/letter/a/c57346/32.png) [@Adrian\_2](https://discuss.elastic.co/u/Adrian_2)\
**Post date:** [September 9, 2013, 7:13pm UTC](https://discuss.elastic.co/t/searchhit-java-api/13518/7 "2013-09-09T19:13:25Z")

</div>

On Mon, Sep 09, 2013 at 05:27:06PM +0200, David Pilato wrote:

David,

> As you have the full map with getFields(), why not simply iterate other it?  
> Or ask the map to give you the field you want?

Absolutely. I just wondered why almost all properties of SearchHit are  
accessible using getters but field.

> Could you share with a Gist some code? It could help me to have a better  
> picture here. I'm probably missing something.

If there would exist a getField(String fieldname) method access to the value  
would be as follows, given a List of SearchHit is referenced as "hits":

\<hits : { hit | \< hit.fields.keys : { key | : \<hit.field(key)\> } \> } \>

in contrast to (which accesses the map value)

\<hits : { hit | \< hit.fields.keys : { key | : \<hit.fields.(key)\> } \> } \>

Best regards, Adrian

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:** [July 6, 2017, 2:17am UTC](https://discuss.elastic.co/t/searchhit-java-api/13518/8 "2017-07-06T02:17:25Z")

</div>


