# Is it possible to use String as \_id?

**URL:** <https://discuss.elastic.co/t/is-it-possible-to-use-string-as--id/17236>\
**Category:** Elasticsearch\
**Created:** [April 28, 2014, 2:39pm UTC](https://discuss.elastic.co/t/is-it-possible-to-use-string-as--id/17236 "2014-04-28T14:39:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yz1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yz1/32/1611_2.png) [@Yz1](https://discuss.elastic.co/u/Yz1)\
**Post date:** [April 28, 2014, 2:39pm UTC](https://discuss.elastic.co/t/is-it-possible-to-use-string-as--id/17236/1 "2014-04-28T14:39:33Z")

</div>

Through my experiment, it seems not possible to use string as primary key  
in Elasticsearch.  
If type String is used , then the \_id will be something like this:  
"\_id":"[B@fe583b"  
which uses the object address in jvm instead of the real value.  
So, is there any way to generate a composite \_id from two integer value?

--  
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/f073e04b-f2a1-4e5a-a7e0-ff93727f6e9f%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/f073e04b-f2a1-4e5a-a7e0-ff93727f6e9f%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:** [April 28, 2014, 2:56pm UTC](https://discuss.elastic.co/t/is-it-possible-to-use-string-as--id/17236/2 "2014-04-28T14:56:57Z")

</div>

The \_id (metadata \_id, that is) is a string value.

The value of the \_id string is whatever you set it to (or else a long  
string automatically generated by Elasticsearch when the document is  
created). You have complete freedom to set it to any string value you wish.

The \_id metadata is the closest thing ES has to a unique constraint, and I  
use it quite effectively in this way.

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/a311ee25-b4e9-4155-9543-55eb7a199bcd%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/a311ee25-b4e9-4155-9543-55eb7a199bcd%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [April 28, 2014, 3:00pm UTC](https://discuss.elastic.co/t/is-it-possible-to-use-string-as--id/17236/3 "2014-04-28T15:00:42Z")

</div>

Can you share the code that you used to trigger this issue?

On Mon, Apr 28, 2014 at 4:39 PM, Yz [yingzhong.xu@gmail.com](mailto:yingzhong.xu@gmail.com) wrote:

> Through my experiment, it seems not possible to use string as primary key  
> in Elasticsearch.  
> If type String is used , then the \_id will be something like this:  
> "\_id":"[B@fe583b"  
> which uses the object address in jvm instead of the real value.  
> So, is there any way to generate a composite \_id from two integer value?
> 
> --  
> 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/f073e04b-f2a1-4e5a-a7e0-ff93727f6e9f%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/f073e04b-f2a1-4e5a-a7e0-ff93727f6e9f%40googlegroups.com)[https://groups.google.com/d/msgid/elasticsearch/f073e04b-f2a1-4e5a-a7e0-ff93727f6e9f%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/f073e04b-f2a1-4e5a-a7e0-ff93727f6e9f%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
Adrien Grand

--  
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/CAL6Z4j6%3D%2BZ0sTOUZpaaW6stOESDn67WSAskNXd88wiFgfp7RTQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j6%3D%2BZ0sTOUZpaaW6stOESDn67WSAskNXd88wiFgfp7RTQ%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Yz1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yz1/32/1611_2.png) [@Yz1](https://discuss.elastic.co/u/Yz1)\
**Post date:** [April 29, 2014, 4:13am UTC](https://discuss.elastic.co/t/is-it-possible-to-use-string-as--id/17236/4 "2014-04-29T04:13:46Z")

</div>

So, it seems to be mysql\_jdbc\_river's problem?  
Here is my sql query:  
"SELECT concat(fid,cmid) as \_id .... FROM forum JOIN comment ..."  
I set the concatenation of two integer fields to be the primary key and  
causes the problem I described above..  
Now I am dividing two tables into separate Types within an Index and using  
their own integer id as the primary key.

On Monday, April 28, 2014 11:00:42 PM UTC+8, Adrien Grand wrote:

> Can you share the code that you used to trigger this issue?
> 
> On Mon, Apr 28, 2014 at 4:39 PM, Yz \<[yingzh...@gmail.com](mailto:yingzh...@gmail.com) \<javascript:\>\>wrote:
> 
> > Through my experiment, it seems not possible to use string as primary key  
> > in Elasticsearch.  
> > If type String is used , then the \_id will be something like this:  
> > "\_id":"[B@fe583b"  
> > which uses the object address in jvm instead of the real value.  
> > So, is there any way to generate a composite \_id from two integer value?
> > 
> > --  
> > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/f073e04b-f2a1-4e5a-a7e0-ff93727f6e9f%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/f073e04b-f2a1-4e5a-a7e0-ff93727f6e9f%40googlegroups.com)[https://groups.google.com/d/msgid/elasticsearch/f073e04b-f2a1-4e5a-a7e0-ff93727f6e9f%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/f073e04b-f2a1-4e5a-a7e0-ff93727f6e9f%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> 
> --  
> Adrien Grand

--  
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/9eaa22ea-8102-40a7-9f84-97f571ce9ef7%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/9eaa22ea-8102-40a7-9f84-97f571ce9ef7%40googlegroups.com).  
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:32am UTC](https://discuss.elastic.co/t/is-it-possible-to-use-string-as--id/17236/5 "2017-07-06T01:32:57Z")

</div>


