# Index a substring

**URL:** <https://discuss.elastic.co/t/index-a-substring/183760>\
**Category:** Kibana\
**Created:** [May 31, 2019, 3:43pm UTC](https://discuss.elastic.co/t/index-a-substring/183760 "2019-05-31T15:43:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![msalesb](https://avatars.discourse-cdn.com/v4/letter/m/c6cbf5/32.png) [@msalesb](https://discuss.elastic.co/u/msalesb)\
**Post date:** [May 31, 2019, 3:43pm UTC](https://discuss.elastic.co/t/index-a-substring/183760/1 "2019-05-31T15:43:37Z")

</div>

I am indexing bibliographic data with Kibana and I want to index just a substring of a field.

The field has the following type of data and I would like to index just the data in bold, which is always in the same position, 9 to 12.

Here’s an example:

20010525d **1881** 1888m y0pory01030103ba

Is there any way of doing it?

Thank you for your help.

---

<div class="post-metadata">

**Author:** ![cjcenizal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cjcenizal/32/11216_2.png) [@cjcenizal](https://discuss.elastic.co/u/cjcenizal)\
**Post date:** [May 31, 2019, 10:38pm UTC](https://discuss.elastic.co/t/index-a-substring/183760/2 "2019-05-31T22:38:51Z")

</div>

Hi Miguel, by default all nodes allow you to specify [ingest pipelines](https://www.elastic.co/guide/en/elasticsearch/reference/current/ingest.html) on them, which allow you to define ways to process ingested data.

In your case, you can specify an ingest pipeline that uses a [script processor](https://www.elastic.co/guide/en/elasticsearch/reference/current/script-processor.html) to extract the substring and assign it as a field to the document. In the example below, this pipeline is called `extract-substring`.

```auto
PUT _ingest/pipeline/extract-substring
{
  "description" : "Extract a substring from a serial number",
  "processors" : [
    {
      "script": {
          "source": """
            ctx.extractedSubstring = ctx.sourceField.substring(9, 13)
          """
      }
    }
  ]
}

```

If you were to ingest a document and assign this pipeline like this:

```auto
PUT test/_doc/test-document?pipeline=extract-substring
{
  "sourceField": "20010525d18811888m y0pory01030103ba"
}

```

Then the indexed document will have this resulting shape:

```auto
{
  "sourceField" : "20010525d18811888m y0pory01030103ba",
  "extracted" : "1881"
}

```

---

<div class="post-metadata">

**Author:** ![msalesb](https://avatars.discourse-cdn.com/v4/letter/m/c6cbf5/32.png) [@msalesb](https://discuss.elastic.co/u/msalesb)\
**Post date:** [June 1, 2019, 11:56am UTC](https://discuss.elastic.co/t/index-a-substring/183760/3 "2019-06-01T11:56:33Z")

</div>

Hi CJ,

Thank you very much for your answer and for the great explanation!

Best regards!

---

<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 29, 2019, 11:56am UTC](https://discuss.elastic.co/t/index-a-substring/183760/4 "2019-06-29T11:56:33Z")

</div>

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