# Extract id field

**URL:** <https://discuss.elastic.co/t/extract-id-field/18735>\
**Category:** Elasticsearch\
**Created:** [July 18, 2014, 12:48pm UTC](https://discuss.elastic.co/t/extract-id-field/18735 "2014-07-18T12:48:14Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Giuseppe\_Longo](https://avatars.discourse-cdn.com/v4/letter/g/46a35a/32.png) [@Giuseppe\_Longo](https://discuss.elastic.co/u/Giuseppe_Longo)\
**Post date:** [July 18, 2014, 12:48pm UTC](https://discuss.elastic.co/t/extract-id-field/18735/1 "2014-07-18T12:48:14Z")

</div>

Hi,  
following the documentation here  
[http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-id-field.html](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-id-field.html)

I've declared path mapping between \_id and a field named "table\_id",  
but when doing query the result doesn't contain the table\_id field.

Looking at the example in the doc, it contains the post\_id field.

This is the mapping:

{  
"test" : {  
"mappings" : {  
"table" : {  
"\_id" : {  
"path" : "table\_id"  
},  
"properties" : {  
"name" : {  
"type" : "string",  
"store" : true  
},  
"table\_id" : {  
"type" : "long",  
"store" : true  
}  
}  
}  
}  
}

am I missing anything?  
Thanks

--  
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/66e68abe-7c84-41d9-9eee-54a7ea67450e%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/66e68abe-7c84-41d9-9eee-54a7ea67450e%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:** [July 18, 2014, 12:51pm UTC](https://discuss.elastic.co/t/extract-id-field/18735/2 "2014-07-18T12:51:01Z")

</div>

Could you create a full script which would help to understand what you exactly did?

See [http://www.elasticsearch.org/help/](http://www.elasticsearch.org/help/)

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

Le 18 juillet 2014 à 14:48:18, Giuseppe Longo ([giuseppelng@gmail.com](mailto:giuseppelng@gmail.com)) a écrit:

Hi,  
following the documentation here [http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-id-field.html](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-id-field.html)  
I've declared path mapping between \_id and a field named "table\_id",  
but when doing query the result doesn't contain the table\_id field.

Looking at the example in the doc, it contains the post\_id field.

This is the mapping:

{  
"test" : {  
"mappings" : {  
"table" : {  
"\_id" : {  
"path" : "table\_id"  
},  
"properties" : {  
"name" : {  
"type" : "string",  
"store" : true  
},  
"table\_id" : {  
"type" : "long",  
"store" : true  
}  
}  
}  
}  
}

## am I missing anything? Thanks

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/66e68abe-7c84-41d9-9eee-54a7ea67450e%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/66e68abe-7c84-41d9-9eee-54a7ea67450e%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/etPan.53c91835.109cf92e.38f%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.53c91835.109cf92e.38f%40MacBook-Air-de-David.local).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Giuseppe\_Longo](https://avatars.discourse-cdn.com/v4/letter/g/46a35a/32.png) [@Giuseppe\_Longo](https://discuss.elastic.co/u/Giuseppe_Longo)\
**Post date:** [July 18, 2014, 1:13pm UTC](https://discuss.elastic.co/t/extract-id-field/18735/3 "2014-07-18T13:13:40Z")

</div>

Hi David,  
you can find the script here: [http://pastebin.com/6EdQSCft](http://pastebin.com/6EdQSCft)

As you can see, the result of GET request is:

{name: "test"}

but it should be:

{  
table\_id: 1  
name: "test"  
}

Thanks

--  
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/085356cf-fbb5-4aaa-8321-ece1bea5ac79%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/085356cf-fbb5-4aaa-8321-ece1bea5ac79%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:** [July 18, 2014, 1:16pm UTC](https://discuss.elastic.co/t/extract-id-field/18735/4 "2014-07-18T13:16:22Z")

</div>

I see.

Actually, setting path to `_id` do exactly the opposite as what you are expecting:

It extracts at index time the \_id value from the source document.

So, if you send a document like:

{  
"table\_id":"my\_id"  
}

The elasticsearch document id for this doc will be "my\_id".

Makes sense?

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

Le 18 juillet 2014 à 15:13:49, Giuseppe Longo ([giuseppelng@gmail.com](mailto:giuseppelng@gmail.com)) a écrit:

Hi David,  
you can find the script here: [http://pastebin.com/6EdQSCft](http://pastebin.com/6EdQSCft)

As you can see, the result of GET request is:

{name: "test"}

but it should be:

{  
table\_id: 1  
name: "test"  
}

## Thanks

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/085356cf-fbb5-4aaa-8321-ece1bea5ac79%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/085356cf-fbb5-4aaa-8321-ece1bea5ac79%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/etPan.53c91e26.4e6afb66.38f%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.53c91e26.4e6afb66.38f%40MacBook-Air-de-David.local).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Giuseppe\_Longo](https://avatars.discourse-cdn.com/v4/letter/g/46a35a/32.png) [@Giuseppe\_Longo](https://discuss.elastic.co/u/Giuseppe_Longo)\
**Post date:** [July 18, 2014, 1:21pm UTC](https://discuss.elastic.co/t/extract-id-field/18735/5 "2014-07-18T13:21:18Z")

</div>

I'm not sure to understand you.  
I've followed step by step the tutorial, it's strange that setting path to  
`_id` do the opposite currently, or not?

--  
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/4ead76cd-13e3-49e3-a217-852c3f865c9a%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/4ead76cd-13e3-49e3-a217-852c3f865c9a%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:** [July 18, 2014, 1:25pm UTC](https://discuss.elastic.co/t/extract-id-field/18735/6 "2014-07-18T13:25:07Z")

</div>

If you are referring to [http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-id-field.html#mapping-id-field](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-id-field.html#mapping-id-field)

It describes what I wrote.

The \_id mapping can also be associated with a path that will be used to extract the id from a different location in the source document. For example, having the following mapping:

{  
"tweet" : {  
"\_id" : {  
"path" : "post\_id"  
}  
}  
}  
Will cause 1 to be used as the id for:

{  
"message" : "You know, for Search",  
"post\_id" : "1"  
}

^^^^ This means that if you send the above document, elasticsearch will extract the \_id from the \_source.post\_id field.

Elasticsearch never modifies your \_source document (unless you use scripts or include/exclude features).

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

Le 18 juillet 2014 à 15:21:24, Giuseppe Longo ([giuseppelng@gmail.com](mailto:giuseppelng@gmail.com)) a écrit:

## I'm not sure to understand you. I've followed step by step the tutorial, it's strange that setting path to `_id` do the opposite currently, or not?

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/4ead76cd-13e3-49e3-a217-852c3f865c9a%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/4ead76cd-13e3-49e3-a217-852c3f865c9a%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/etPan.53c92033.628c895d.38f%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.53c92033.628c895d.38f%40MacBook-Air-de-David.local).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Giuseppe\_Longo](https://avatars.discourse-cdn.com/v4/letter/g/46a35a/32.png) [@Giuseppe\_Longo](https://discuss.elastic.co/u/Giuseppe_Longo)\
**Post date:** [July 18, 2014, 1:28pm UTC](https://discuss.elastic.co/t/extract-id-field/18735/7 "2014-07-18T13:28:42Z")

</div>

It's clear now thanks, I'd ask another question:  
There is a way to include the `_id` into the response for a GET request?

--  
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/f426d153-e5bc-4483-b272-133853097b68%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/f426d153-e5bc-4483-b272-133853097b68%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:** [July 18, 2014, 1:32pm UTC](https://discuss.elastic.co/t/extract-id-field/18735/8 "2014-07-18T13:32:42Z")

</div>

It's already here:

GET test/test/1

{  
"\_index": "test",  
"\_type": "test",  
"\_id": "1",  
"\_version": 1,  
"found": true,  
"\_source": {  
"foo": "bar"  
}  
}

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

Le 18 juillet 2014 à 15:28:48, Giuseppe Longo ([giuseppelng@gmail.com](mailto:giuseppelng@gmail.com)) a écrit:

## It's clear now thanks, I'd ask another question: There is a way to include the `_id` into the response for a GET request?

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/f426d153-e5bc-4483-b272-133853097b68%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/f426d153-e5bc-4483-b272-133853097b68%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/etPan.53c921fa.75a2a8d4.38f%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.53c921fa.75a2a8d4.38f%40MacBook-Air-de-David.local).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Giuseppe\_Longo](https://avatars.discourse-cdn.com/v4/letter/g/46a35a/32.png) [@Giuseppe\_Longo](https://discuss.elastic.co/u/Giuseppe_Longo)\
**Post date:** [July 18, 2014, 1:35pm UTC](https://discuss.elastic.co/t/extract-id-field/18735/9 "2014-07-18T13:35:39Z")

</div>

Ok, then I can extract it directly.  
Thanks for your clarification 🙂

--  
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/ff362026-d93e-4482-9985-017f5a4edba6%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/ff362026-d93e-4482-9985-017f5a4edba6%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:** [July 18, 2014, 2:18pm UTC](https://discuss.elastic.co/t/extract-id-field/18735/10 "2014-07-18T14:18:14Z")

</div>

Why do you want to extract something you already have?

I mean that when you run GET /index/type/id

You already know the id!

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 18 juil. 2014 à 15:35, Giuseppe Longo [giuseppelng@gmail.com](mailto:giuseppelng@gmail.com) a écrit :

## Ok, then I can extract it directly. Thanks for your clarification 🙂

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/ff362026-d93e-4482-9985-017f5a4edba6%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/ff362026-d93e-4482-9985-017f5a4edba6%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/DDDA6D29-2E20-4DBF-BBFF-671E04DD467E%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/DDDA6D29-2E20-4DBF-BBFF-671E04DD467E%40pilato.fr).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:14am UTC](https://discuss.elastic.co/t/extract-id-field/18735/11 "2017-07-06T01:14:52Z")

</div>


