Let's say I have a tag
type in an ElasticSearch index, with the following mapping:
{
"tag": {
"properties": {
"tag": {"type": "string", "store": "yes"},
"aliases": {"type": "string"}
}
}
}
Each entry is a tag, and an array of aliases to that tag. Here is an example item:
{
"word": "weak",
"aliases": ["anemic", "anaemic", "faint", "flimsy"]
}
From time to time, I want to add new tag words with their aliases, and add new aliases to existing tag words.
Adding new tag words with their aliases is easy, it's just a new Document. However, how can I add new aliases to existing tag words in a sane way?
I know I can just search for the tag word, get its document, search to see if the alias already exists in the array of aliases, if not add it, than save. However - this does not sound like a good solution.
Is there a way to do a bulk update?
Try this using _bulk:
http://127.0.0.1:9200/myindex/type/_bulk
{
"update": {
"_index": "myindex",
"_type": "type",
"_id": "myid"
}
}{
"doc": {
"field": "new value"
}
}{
"update": {
"_index": "myindex",
"_type": "type",
"_id": "id"
}
}{
"doc": {
"field": "new value"
}
}
This works for me.
input_list.dat:
{ "index" : { "_index": "my_index", "_type": "my_type", "_id": "existing-value" } }
{ "Field_to_update": "New_Value" }
{ "index" : { "_index": "my_index", "_type": "my_type", "_id": "existing_value" } }
{ "Field_to_update": "New_Value" }
Command:
curl -k -XPOST 'https://my_host:9200/my_url/_bulk' --data-binary "@input_list.dat"; echo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With