# Can I retrieve the payload of an indexed term in \_search or \_mget?

**URL:** <https://discuss.elastic.co/t/can-i-retrieve-the-payload-of-an-indexed-term-in--search-or--mget/37509>\
**Category:** Elasticsearch\
**Created:** [December 17, 2015, 8:15pm UTC](https://discuss.elastic.co/t/can-i-retrieve-the-payload-of-an-indexed-term-in--search-or--mget/37509 "2015-12-17T20:15:34Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![rjprice72](https://avatars.discourse-cdn.com/v4/letter/r/a3d4f5/32.png) [@rjprice72](https://discuss.elastic.co/u/rjprice72)\
**Post date:** [December 17, 2015, 8:15pm UTC](https://discuss.elastic.co/t/can-i-retrieve-the-payload-of-an-indexed-term-in--search-or--mget/37509/1 "2015-12-17T20:15:34Z")

</div>

We use a custom analyzer/token-filter on an index to produce some payload data on a specific term that gets added to the inverted index of the field. This payload supports a custom query, but sometimes it would be useful to access this payload for other external purposes.

Is it possible to retrieve the payload of an indexed term as part of the document data retrieved via a search, or a multi-get, or some other way?

Or, alternatively, is it possible to define a plugin that can manipulate the document data added to an index before any analyzer starts to analyze the fields so that we can add the computed data to the document and pass it as payload too?

Thanks!

---

<div class="post-metadata">

**Author:** ![jimczi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jimczi/32/47985_2.png) [@jimczi](https://discuss.elastic.co/u/jimczi)\
**Post date:** [December 17, 2015, 8:38pm UTC](https://discuss.elastic.co/t/can-i-retrieve-the-payload-of-an-indexed-term-in--search-or--mget/37509/2 "2015-12-17T20:38:04Z")

</div>

You can use the term vectors to retrieve the payloads associated to the analyzed terms of a specific document:  
If it's for debug you can generate them on the fly, if speed matters then you'll need to store them and not forget that it comes with a cost 😉  
Check this page for a full description:  
[https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-termvectors.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-termvectors.html)

---

<div class="post-metadata">

**Author:** ![rjprice72](https://avatars.discourse-cdn.com/v4/letter/r/a3d4f5/32.png) [@rjprice72](https://discuss.elastic.co/u/rjprice72)\
**Post date:** [December 17, 2015, 9:16pm UTC](https://discuss.elastic.co/t/can-i-retrieve-the-payload-of-an-indexed-term-in--search-or--mget/37509/3 "2015-12-17T21:16:41Z")

</div>

Thanks! This should do what I need. I appreciate the fast reply!

For completeness, do you know of a way to do the alternative I mentioned, ie: define a plugin that can manipulate the document data added to an index before any analyzer starts to analyze the fields so that we can add the computed data to the document and pass it as payload too?

---

<div class="post-metadata">

**Author:** ![jimczi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jimczi/32/47985_2.png) [@jimczi](https://discuss.elastic.co/u/jimczi)\
**Post date:** [December 18, 2015, 8:56am UTC](https://discuss.elastic.co/t/can-i-retrieve-the-payload-of-an-indexed-term-in--search-or--mget/37509/4 "2015-12-18T08:56:21Z")

</div>

You can check the mapper plugins:  
[https://www.elastic.co/guide/en/elasticsearch/plugins/current/mapper.html](https://www.elastic.co/guide/en/elasticsearch/plugins/current/mapper.html)  
If you define your own mapper then you should be able to manipulate your field and act on it before analysis.

---

<div class="post-metadata">

**Author:** ![cbuescher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cbuescher/32/60402_2.png) [@cbuescher](https://discuss.elastic.co/u/cbuescher)\
**Post date:** [December 18, 2015, 9:27am UTC](https://discuss.elastic.co/t/can-i-retrieve-the-payload-of-an-indexed-term-in--search-or--mget/37509/5 "2015-12-18T09:27:14Z")

</div>

Hi,

for the purpose of enriching documents before analysis, theres also current "work in progress" on a new type of node currently called the [Ingest Node](https://github.com/elastic/elasticsearch/issues/14049) which might be worth looking at once it is released. Not sure when it is going to be out, but maybe you like to take a sneak peak already.

---

<div class="post-metadata">

**Author:** ![rjprice72](https://avatars.discourse-cdn.com/v4/letter/r/a3d4f5/32.png) [@rjprice72](https://discuss.elastic.co/u/rjprice72)\
**Post date:** [December 21, 2015, 5:14pm UTC](https://discuss.elastic.co/t/can-i-retrieve-the-payload-of-an-indexed-term-in--search-or--mget/37509/6 "2015-12-21T17:14:31Z")

</div>

Thanks for the pointer!

The MapperSizePlugin is interesting as it adds a new \_size field to the document. I need to add a new field whose value is an object with a document-dependent set of keys.

Do you happen to know if this is possible/allowed?

I would like to pursue this approach, but it would be nice to know in advance if this cannot work.

---

<div class="post-metadata">

**Author:** ![rjprice72](https://avatars.discourse-cdn.com/v4/letter/r/a3d4f5/32.png) [@rjprice72](https://discuss.elastic.co/u/rjprice72)\
**Post date:** [December 21, 2015, 5:15pm UTC](https://discuss.elastic.co/t/can-i-retrieve-the-payload-of-an-indexed-term-in--search-or--mget/37509/7 "2015-12-21T17:15:34Z")

</div>

Thanks for the reference Christoph. That will be very useful once it is ready.

---

<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 5, 2017, 11:29pm UTC](https://discuss.elastic.co/t/can-i-retrieve-the-payload-of-an-indexed-term-in--search-or--mget/37509/8 "2017-07-05T23:29:30Z")

</div>


