1

SQL has the "INSERT INTO ... SELECT" statement to fill a table with data from a query. Does anything like this exist for Elasticsearch?

This would prevent me from mass deleting data from an existing index using a query - which is something the official Elasticsearch 2.1 guide warns against:

Don’t use delete-by-query to clean out all or most documents in an index. Rather create a new index and perhaps reindex the documents you want to keep.

(Source: https://www.elastic.co/guide/en/elasticsearch/plugins/current/plugins-delete-by-query.html).

2 Answers 2

4

You can use the excellent utility from taskrabbit called elasticdump.

There are many options to customize the import process. In your case, I would use the searchBody option and go with something like this:

elasticdump \
  --input=http://HOST:9200/source_index \
  --output=http://HOST:9200/target_index \
  --bulk=true \
  --searchBody='{"query": { "match_all": {} } }'

You can customize the query and only the matched documents from the source_index will be copied over to the target_index

Sign up to request clarification or add additional context in comments.

Comments

0

Take a look at the create index API: https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html

PUT /test
{
  "settings": {
    "number_of_shards": 1
  },
  "mappings": {
    "properties": {
      "field1": { "type": "text" }
    }
  }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.