# Extract routing value from document - bulk index

**URL:** <https://discuss.elastic.co/t/extract-routing-value-from-document-bulk-index/273404>\
**Category:** Elasticsearch\
**Created:** [May 19, 2021, 12:29pm UTC](https://discuss.elastic.co/t/extract-routing-value-from-document-bulk-index/273404 "2021-05-19T12:29:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![brjisc](https://avatars.discourse-cdn.com/v4/letter/b/6bbea6/32.png) [@brjisc](https://discuss.elastic.co/u/brjisc)\
**Post date:** [May 19, 2021, 12:29pm UTC](https://discuss.elastic.co/t/extract-routing-value-from-document-bulk-index/273404/1 "2021-05-19T12:29:02Z")

</div>

The documentation states " When setting up explicit mapping, you can also use the `_routing` field to direct the index operation to extract the routing value from the document itself"

How is the routing information represented in the document?  
The \_routing field cannot be used is it is a metadata field.

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [May 25, 2021, 12:05pm UTC](https://discuss.elastic.co/t/extract-routing-value-from-document-bulk-index/273404/2 "2021-05-25T12:05:15Z")

</div>

You can use a pipeline for this

```auto
PUT _ingest/pipeline/my-pipeline
{
  "processors": [
    {
      "script": {
        "lang": "painless",
        "source": "ctx._routing = ctx.key"
      }
    }
  ]
}

```

And then configure the index to always use that pipeline.

---

<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:** [June 22, 2021, 12:06pm UTC](https://discuss.elastic.co/t/extract-routing-value-from-document-bulk-index/273404/3 "2021-06-22T12:06:13Z")

</div>

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