Extract id field


(Giuseppe Longo) #1

Hi,
following the documentation here
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/66e68abe-7c84-41d9-9eee-54a7ea67450e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(David Pilato) #2

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

See http://www.elasticsearch.org/help/

--
David Pilato | Technical Advocate | Elasticsearch.com
@dadoonet | @elasticsearchfr

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

Hi,
following the documentation here 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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/66e68abe-7c84-41d9-9eee-54a7ea67450e%40googlegroups.com.
For more options, visit 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.
To view this discussion on the web visit 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.


(Giuseppe Longo) #3

Hi David,
you can find the script here: 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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/085356cf-fbb5-4aaa-8321-ece1bea5ac79%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(David Pilato) #4

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
@dadoonet | @elasticsearchfr

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

Hi David,
you can find the script here: 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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/085356cf-fbb5-4aaa-8321-ece1bea5ac79%40googlegroups.com.
For more options, visit 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.
To view this discussion on the web visit 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.


(Giuseppe Longo) #5

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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/4ead76cd-13e3-49e3-a217-852c3f865c9a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(David Pilato) #6

If you are referring to 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
@dadoonet | @elasticsearchfr

Le 18 juillet 2014 à 15:21:24, Giuseppe Longo (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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/4ead76cd-13e3-49e3-a217-852c3f865c9a%40googlegroups.com.
For more options, visit 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.
To view this discussion on the web visit 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.


(Giuseppe Longo) #7

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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/f426d153-e5bc-4483-b272-133853097b68%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(David Pilato) #8

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
@dadoonet | @elasticsearchfr

Le 18 juillet 2014 à 15:28:48, Giuseppe Longo (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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/f426d153-e5bc-4483-b272-133853097b68%40googlegroups.com.
For more options, visit 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.
To view this discussion on the web visit 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.


(Giuseppe Longo) #9

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

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/ff362026-d93e-4482-9985-017f5a4edba6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(David Pilato) #10

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 :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 18 juil. 2014 à 15:35, Giuseppe Longo giuseppelng@gmail.com a écrit :

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

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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/ff362026-d93e-4482-9985-017f5a4edba6%40googlegroups.com.
For more options, visit 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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/DDDA6D29-2E20-4DBF-BBFF-671E04DD467E%40pilato.fr.
For more options, visit https://groups.google.com/d/optout.


(system) #11