DEV Community

Mallikarjun H T
Mallikarjun H T

Posted on • Edited on

4 3

Elastic Search Reindexing

Reindex API

Documents are copied from one location to another.
The document source is extracted from the source index and the documents are indexed in the destination index. You can reindex a selection of the documents or transfer all items to the target index.

Reindexing requires that _source be enabled for all documents in the source.
Before invoking _reindex, the destination should be specified as desired. The settings from the source or its related template are not copied when you reindex.
Mappings, shard counts, replicas, and other parameters must be set up ahead of time.

Querry

POST _reindex
{
  "source": {
    "index": "my-index-000001"
  },
  "dest": {
    "index": "my-new-index-000001"
  }
}
Enter fullscreen mode Exit fullscreen mode

OR

curl -X POST "localhost:9200/_reindex?pretty" -H 'Content-Type: application/json' -d'
{
  "source": {
    "index": "my-index-000001"
  },
  "dest": {
    "index": "my-new-index-000001"
  }
}'
Enter fullscreen mode Exit fullscreen mode

_reindex with scripts

We can use Painless scripting to run our querry.

POST _reindex
{
  "source": {
    "index": "my-index-000001"
  },
  "dest": {
    "index": "my-new-index-000001"
  },
  "script": {
    "inline": "ctx._source.field = Long.parseLong(ctx._source.field)"
  }
}

Enter fullscreen mode Exit fullscreen mode

Conclusion

Avoide Reindexing!
If reindexing is absolutely necessary, this Querry can be used.
If we need to convert one data type to another, we may use scripts to our benefit.
If you are familiar with pipelines, we can do much more sophisticated tasks with ease.

Resources

ElasticSearch

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Billboard image

Try REST API Generation for MS SQL Server.

DevOps for Private APIs. With DreamFactory API Generation, you get:

  • Auto-generated live APIs mapped from database schema
  • Interactive Swagger API documentation
  • Scripting engine to customize your API
  • Built-in role-based access control

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay