# How can I automate looping through an index and running a pipeline against each document?

**URL:** <https://discuss.elastic.co/t/how-can-i-automate-looping-through-an-index-and-running-a-pipeline-against-each-document/357719>\
**Category:** Elasticsearch\
**Tags:** ingest-pipeline\
**Created:** [April 18, 2024, 2:19pm UTC](https://discuss.elastic.co/t/how-can-i-automate-looping-through-an-index-and-running-a-pipeline-against-each-document/357719 "2024-04-18T14:19:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jingyi\_Wang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jingyi_wang/32/121787_2.png) [@Jingyi\_Wang](https://discuss.elastic.co/u/Jingyi_Wang)\
**Post date:** [April 18, 2024, 2:19pm UTC](https://discuss.elastic.co/t/how-can-i-automate-looping-through-an-index-and-running-a-pipeline-against-each-document/357719/1 "2024-04-18T14:19:22Z")

</div>

I have index with documents like:

```auto
[
      {
        "_index" : "converted-user",
        "_type" : "_doc",
        "_id" : "dTXSY0KNxU08jKDnZcc-nbkAAAAAAAAA",
        "_score" : 1.0,
        "_source" : {
          "username" : "A"
        }
      },
      {
        "_index" : "converted-user",
        "_type" : "_doc",
        "_id" : "dfSD8G1Jr5RDBni4Hsv9LWcAAAAAAAAA",
        "_score" : 1.0,
        "_source" : {
          "username" : "B"
        }
      }
    ]

```

I also have an enrich pipeline to enrich this document by username and stored them under a new index.

```auto
PUT /_ingest/pipeline/username_lookup
{
  "processors": [
    {
      "enrich": {
        "description": "Add speed and router info based on username",
        "policy_name": "username_policy",
        "field": "username",
        "target_field": "scan_data",
        "max_matches": "2"
      }
    }
  ]
}

```

I can manually enrich each documents by running:

```auto
PUT /convert_user_enriched/_doc/dfSD8G1Jr5RDBni4Hsv9LWcAAAAAAAAA?pipeline=username_lookup
{
  "username": "B"
}

```

BUT now the questions is how can I automate this enrich process by going the "converted-user" index automatically and implement the pipeline against each document.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 18, 2024, 6:38pm UTC](https://discuss.elastic.co/t/how-can-i-automate-looping-through-an-index-and-running-a-pipeline-against-each-document/357719/2 "2024-04-18T18:38:34Z")

</div>

Most likely you need to use the reindex API
