# Create a field base on other docs results in the same index

**URL:** <https://discuss.elastic.co/t/create-a-field-base-on-other-docs-results-in-the-same-index/226071>\
**Category:** Kibana\
**Tags:** painless\
**Created:** [April 1, 2020, 2:52pm UTC](https://discuss.elastic.co/t/create-a-field-base-on-other-docs-results-in-the-same-index/226071 "2020-04-01T14:52:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![oula\_oula](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/oula_oula/32/63182_2.png) [@oula\_oula](https://discuss.elastic.co/u/oula_oula)\
**Post date:** [April 1, 2020, 2:52pm UTC](https://discuss.elastic.co/t/create-a-field-base-on-other-docs-results-in-the-same-index/226071/1 "2020-04-01T14:52:29Z")

</div>

Hi,  
I'm using scripted fields and I've see that it's applied on docs index one after an other.  
I need to combine field value of the current field with an other doc's field in the same index.  
So is it possible to query a doc field value that is somewhere in my index in the painless scripted field ?

Thank you

---

<div class="post-metadata">

**Author:** ![flash1293](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flash1293/32/41227_2.png) [@flash1293](https://discuss.elastic.co/u/flash1293)\
**Post date:** [April 1, 2020, 3:36pm UTC](https://discuss.elastic.co/t/create-a-field-base-on-other-docs-results-in-the-same-index/226071/2 "2020-04-01T15:36:19Z")

</div>

You can't do that with scripted fields, mostly for performance reasons.

Instead, it is recommended to do these things before the documents get indexed in Elasticsearch.

It's possible to do this in your own application (before ingesting, doing a request to Elasticsearch and basically moving the script into your application).

However it makes sense to solve it within the Elastic stack. You can use an [ingest pipeline](https://www.elastic.co/guide/en/elasticsearch/reference/current/pipeline.html) with an [enrich processor](https://www.elastic.co/guide/en/elasticsearch/reference/7.6/ingest-enriching-data.html) - use it to look up the fields you need and put them into your document - then you can use a [script processor](https://www.elastic.co/guide/en/elasticsearch/reference/7.6/script-processor.html) to execute your script based on the data pulled in from other documents.

---

<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:** [April 29, 2020, 3:36pm UTC](https://discuss.elastic.co/t/create-a-field-base-on-other-docs-results-in-the-same-index/226071/3 "2020-04-29T15:36:29Z")

</div>

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