# Result metadata

**URL:** <https://discuss.elastic.co/t/result-metadata/15234>\
**Category:** Elasticsearch\
**Created:** [January 14, 2014, 2:13pm UTC](https://discuss.elastic.co/t/result-metadata/15234 "2014-01-14T14:13:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Savio\_Teles](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/savio_teles/32/851_2.png) [@Savio\_Teles](https://discuss.elastic.co/u/Savio_Teles)\
**Post date:** [January 14, 2014, 2:13pm UTC](https://discuss.elastic.co/t/result-metadata/15234/1 "2014-01-14T14:13:44Z")

</div>

How can I get the metadata from a query result?

In Java can be implemented like this using SQL:

Statement st = connection.createStatement();  
ResultSet result = st.executeQuery(sql);  
result.getMetaData();

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/b4d14314-13ba-4646-8bd7-541d3a9c5735%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/b4d14314-13ba-4646-8bd7-541d3a9c5735%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![brian\_yoder](https://avatars.discourse-cdn.com/v4/letter/b/f1d935/32.png) [@brian\_yoder](https://discuss.elastic.co/u/brian_yoder)\
**Post date:** [January 14, 2014, 3:35pm UTC](https://discuss.elastic.co/t/result-metadata/15234/2 "2014-01-14T15:35:54Z")

</div>

Savio,

You can get it from the SearchHit. For example:

public void _loadFrom_(SearchHit doc)  
{  
index = doc.getIndex();  
type = doc.getType();  
id = doc.getId();  
version = doc.getVersion();

try  
{  
setTTL(extractTTL(doc));  
}  
catch Exception e)  
{  
ttl = null;  
}  
}

public static String _extractTTL_(SearchHit doc)  
{  
String ttl = null;  
if (doc != null)  
{  
SearchHitField ttlField = doc.field(TTL\_FIELD\_NAME);  
if (ttlField != null)  
{  
Value ttlValue = new Value(ttlField.value());  
if (ttlValue != null)  
return ttlValue.toRawString();  
}  
}  
return ttl;  
}

And you would do something similar for a GetResponse object, too (response  
from a query-by-id).

Hope this helps!

Brian

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/d7388850-8355-408b-81de-8f91a40004fc%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d7388850-8355-408b-81de-8f91a40004fc%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Savio\_Teles](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/savio_teles/32/851_2.png) [@Savio\_Teles](https://discuss.elastic.co/u/Savio_Teles)\
**Post date:** [January 14, 2014, 4:47pm UTC](https://discuss.elastic.co/t/result-metadata/15234/3 "2014-01-14T16:47:54Z")

</div>

So, Have I to extract the Java type of each object of response? There is no  
way to get metadata directly?

Thanks for the answer!

Em terça-feira, 14 de janeiro de 2014 12h13min44s UTC-2, Savio Teles  
escreveu:

> How can I get the metadata from a query result?
> 
> In Java can be implemented like this using SQL:
> 
> Statement st = connection.createStatement();  
> ResultSet result = st.executeQuery(sql);  
> result.getMetaData();

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/233e3754-b1da-482f-8c98-b16a30a87b0b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/233e3754-b1da-482f-8c98-b16a30a87b0b%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [January 14, 2014, 5:24pm UTC](https://discuss.elastic.co/t/result-metadata/15234/4 "2014-01-14T17:24:52Z")

</div>

What metadata are you looking for? Just the column type? Unfortunately  
there is no direct way to get the Java type of each response/field. You can  
retrieve the mapping from the index [1] and determine which field uses  
which type. I am assuming most using the Java API have written their own  
ORM layer. Elasticsearch uses Jackson for JSON, so you can always use it to  
recreate your objects.

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

Cheers,

Ivan

On Tue, Jan 14, 2014 at 8:47 AM, Savio Teles [savioteles@gmail.com](mailto:savioteles@gmail.com) wrote:

> So, Have I to extract the Java type of each object of response? There is  
> no way to get metadata directly?
> 
> Thanks for the answer!
> 
> Em terça-feira, 14 de janeiro de 2014 12h13min44s UTC-2, Savio Teles  
> escreveu:
> 
> > How can I get the metadata from a query result?
> > 
> > In Java can be implemented like this using SQL:
> > 
> > Statement st = connection.createStatement();  
> > ResultSet result = st.executeQuery(sql);  
> > result.getMetaData();
> 
> --  
> 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).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/233e3754-b1da-482f-8c98-b16a30a87b0b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/233e3754-b1da-482f-8c98-b16a30a87b0b%40googlegroups.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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQD73awz3jd%2B%3Dh243%3Dnw\_45rKY%3Dpi1\_%2Bu-Aq-8-RF\_ooyg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQD73awz3jd%2B%3Dh243%3Dnw_45rKY%3Dpi1_%2Bu-Aq-8-RF_ooyg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Savio\_Teles](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/savio_teles/32/851_2.png) [@Savio\_Teles](https://discuss.elastic.co/u/Savio_Teles)\
**Post date:** [January 14, 2014, 6:20pm UTC](https://discuss.elastic.co/t/result-metadata/15234/5 "2014-01-14T18:20:19Z")

</div>

> What metadata are you looking for? Just the column type?

Yes, just the column type.

You can retrieve the mapping from the index [1]

Ok! Tks

Em terça-feira, 14 de janeiro de 2014 12h13min44s UTC-2, Savio Teles  
escreveu:

> How can I get the metadata from a query result?
> 
> In Java can be implemented like this using SQL:
> 
> Statement st = connection.createStatement();  
> ResultSet result = st.executeQuery(sql);  
> result.getMetaData();

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/89e0e3f4-c6bc-45f8-b255-7ac77f3f040d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/89e0e3f4-c6bc-45f8-b255-7ac77f3f040d%40googlegroups.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, 1:56am UTC](https://discuss.elastic.co/t/result-metadata/15234/6 "2017-07-06T01:56:50Z")

</div>


