# Is it possible to use variables in indexed documents in elasticsearch?

**URL:** <https://discuss.elastic.co/t/is-it-possible-to-use-variables-in-indexed-documents-in-elasticsearch/135736>\
**Category:** Elasticsearch\
**Created:** [June 13, 2018, 1:32pm UTC](https://discuss.elastic.co/t/is-it-possible-to-use-variables-in-indexed-documents-in-elasticsearch/135736 "2018-06-13T13:32:28Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![rs123](https://avatars.discourse-cdn.com/v4/letter/r/73ab20/32.png) [@rs123](https://discuss.elastic.co/u/rs123)\
**Post date:** [June 13, 2018, 1:32pm UTC](https://discuss.elastic.co/t/is-it-possible-to-use-variables-in-indexed-documents-in-elasticsearch/135736/1 "2018-06-13T13:32:28Z")

</div>

Is it possible to use variables in indexed documents in elasticsearch?

```
POST somki/_doc/
{
    "suggest": {
        "input": ["my name is x"]
        }
    }
}

```

I want to have x as variable so that when someone search something system should show value of x from another index based on user.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [June 14, 2018, 9:21am UTC](https://discuss.elastic.co/t/is-it-possible-to-use-variables-in-indexed-documents-in-elasticsearch/135736/2 "2018-06-14T09:21:57Z")

</div>

No, you cannot do that.

---

<div class="post-metadata">

**Author:** ![rs123](https://avatars.discourse-cdn.com/v4/letter/r/73ab20/32.png) [@rs123](https://discuss.elastic.co/u/rs123)\
**Post date:** [June 14, 2018, 10:09am UTC](https://discuss.elastic.co/t/is-it-possible-to-use-variables-in-indexed-documents-in-elasticsearch/135736/3 "2018-06-14T10:09:33Z")

</div>

Is it possible to show suggestion as "Something is x and y" where x and y will be different for each user and will have multiple values and those which have highest weight will be shown?

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [June 15, 2018, 4:16am UTC](https://discuss.elastic.co/t/is-it-possible-to-use-variables-in-indexed-documents-in-elasticsearch/135736/4 "2018-06-15T04:16:02Z")

</div>

I guess that depends how you are defining and weighing them.

---

<div class="post-metadata">

**Author:** ![rs123](https://avatars.discourse-cdn.com/v4/letter/r/73ab20/32.png) [@rs123](https://discuss.elastic.co/u/rs123)\
**Post date:** [June 15, 2018, 5:20am UTC](https://discuss.elastic.co/t/is-it-possible-to-use-variables-in-indexed-documents-in-elasticsearch/135736/5 "2018-06-15T05:20:30Z")

</div>

Can you provide an example? I'm new to elasticsearch and did not find much on web about what I'm looking for. Thanks!

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [June 15, 2018, 8:56pm UTC](https://discuss.elastic.co/t/is-it-possible-to-use-variables-in-indexed-documents-in-elasticsearch/135736/6 "2018-06-15T20:56:34Z")

</div>

You need a way to define what these variables are per user and then define weights to them, how you do that isn't really an Elasticsearch thing it's how you structure your document.

---

<div class="post-metadata">

**Author:** ![rs123](https://avatars.discourse-cdn.com/v4/letter/r/73ab20/32.png) [@rs123](https://discuss.elastic.co/u/rs123)\
**Post date:** [June 21, 2018, 1:16pm UTC](https://discuss.elastic.co/t/is-it-possible-to-use-variables-in-indexed-documents-in-elasticsearch/135736/7 "2018-06-21T13:16:33Z")

</div>

Is it possible to show prefix in suggester from different index?  
What I mean is, In documents if I store some strings in prefix field then they are being shown in suggestions but if I want to show prefix from other index, can it be done and how?

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [June 21, 2018, 9:59pm UTC](https://discuss.elastic.co/t/is-it-possible-to-use-variables-in-indexed-documents-in-elasticsearch/135736/8 "2018-06-21T21:59:48Z")

</div>

You'd have to write something entirely custom in your code for that I'd imagine.

---

<div class="post-metadata">

**Author:** ![rs123](https://avatars.discourse-cdn.com/v4/letter/r/73ab20/32.png) [@rs123](https://discuss.elastic.co/u/rs123)\
**Post date:** [June 22, 2018, 5:38am UTC](https://discuss.elastic.co/t/is-it-possible-to-use-variables-in-indexed-documents-in-elasticsearch/135736/9 "2018-06-22T05:38:26Z")

</div>

Thanks

---

<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 20, 2018, 5:38am UTC](https://discuss.elastic.co/t/is-it-possible-to-use-variables-in-indexed-documents-in-elasticsearch/135736/10 "2018-07-20T05:38:38Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
