# Using ids vs natural language

**URL:** <https://discuss.elastic.co/t/using-ids-vs-natural-language/22151>\
**Category:** Elasticsearch\
**Created:** [February 13, 2015, 10:49am UTC](https://discuss.elastic.co/t/using-ids-vs-natural-language/22151 "2015-02-13T10:49:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![noren](https://avatars.discourse-cdn.com/v4/letter/n/f1d935/32.png) [@noren](https://discuss.elastic.co/u/noren)\
**Post date:** [February 13, 2015, 10:49am UTC](https://discuss.elastic.co/t/using-ids-vs-natural-language/22151/1 "2015-02-13T10:49:41Z")

</div>

Hey,

For the following situation:

doc-entry  
{  
"id" : 1,  
"users" : [1001, 2002],  
}

user-entry  
{  
"id": 1001,  
"name": "a"  
},  
{  
"id": 2002,  
"name": "b"  
}

Lets say I search for doc-entries that contains user\_id= 1001, is it  
possible for elasticsearch to automatically map the user id to the user  
object and return something like:

doc-entry  
{  
"id" : 1,  
"users" : ["a", "b"]  
},

And in this case what happens if you want to search doc-estry using a user  
name, could elasticsearch automatically lookup the user id and then search  
the name field?

I have a very relation db like way of thinking, what would best practice be  
when doing something like this in elasticsearch. Could I solve this by  
using natural language as id, e.g. using the user name as id

--  
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/6fb2ff7b-528b-41f9-8a21-e324584785fb%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/6fb2ff7b-528b-41f9-8a21-e324584785fb%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Hannes\_Korte](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hannes_korte/32/909_2.png) [@Hannes\_Korte](https://discuss.elastic.co/u/Hannes_Korte)\
**Post date:** [February 13, 2015, 12:17pm UTC](https://discuss.elastic.co/t/using-ids-vs-natural-language/22151/2 "2015-02-13T12:17:25Z")

</div>

Hi,

if you only want to search for doc-entries by user-names, then you could  
simply store the user-names as IDs. But if you want to search  
doc-entries by user's gender or age for example, then you need some kind  
of relationship between these documents.

If you have a 1:n-relation between docs and users you could use  
parent/child relations. I use these for document tagging for example,  
where the tags are the children of the docs. This way you can search for  
docs having a specific tag, but you can also change the tags without the  
need to re-index the whole document.

AFAIK there is no simple way to get n:m relations. You have to  
denormalize your data in some way.

There is a very helpful blog post about the different possibilities for  
"Managing Relations inside Elasticsearch":

> **[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.

Best regards,  
Hannes

On 13.02.2015 11:49, [noren@sobazaar.com](mailto:noren@sobazaar.com) wrote:

> Hey,
> 
> For the following situation:
> 
> doc-entry  
> {  
> "id" : 1,  
> "users" : [1001, 2002],  
> }
> 
> user-entry  
> {  
> "id": 1001,  
> "name": "a"  
> },  
> {  
> "id": 2002,  
> "name": "b"  
> }
> 
> Lets say I search for doc-entries that contains user\_id= 1001, is it  
> possible for elasticsearch to automatically map the user id to the user  
> object and return something like:
> 
> doc-entry  
> {  
> "id" : 1,  
> "users" : ["a", "b"]  
> },
> 
> And in this case what happens if you want to search doc-estry using a user  
> name, could elasticsearch automatically lookup the user id and then search  
> the name field?
> 
> I have a very relation db like way of thinking, what would best practice be  
> when doing something like this in elasticsearch. Could I solve this by  
> using natural language as id, e.g. using the user name as id

--  
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/54DDEB55.7030500%40hkorte.com](https://groups.google.com/d/msgid/elasticsearch/54DDEB55.7030500%40hkorte.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, 12:32am UTC](https://discuss.elastic.co/t/using-ids-vs-natural-language/22151/3 "2017-07-06T00:32:58Z")

</div>

Closed on July 6, 2017, 12:32am UTC


