Skip to content

Instantly share code, notes, and snippets.

@cherniag
Last active November 1, 2017 12:45
Show Gist options
  • Save cherniag/8d7d2da38076f3a5787479aeb5f90d32 to your computer and use it in GitHub Desktop.
Save cherniag/8d7d2da38076f3a5787479aeb5f90d32 to your computer and use it in GitHub Desktop.
Elasticsearch
1. Create index
curl -X PUT "http://<>:9200/index-name" -d '{
"mappings": {
"record": {
"properties": {
"actionStartedOn": {
"type": "date"
},
"rddCount": {
"type": "long"
},
"rdd_created": {
"type": "long"
},
"rdd_finished": {
"type": "long"
},
"rdd_started": {
"type": "long"
},
"topology_created": {
"type": "long"
},
"topology_finished": {
"type": "long"
},
"topology_started": {
"type": "long"
},
"topology_failed": {
"type": "long"
},
"vis_command_finished": {
"type": "long"
},
"vis_data_succeeded": {
"type": "long"
},
"topology_cancelled": {
"type": "long"
},
"rdd_cancelled": {
"type": "long"
},
"vis": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}'
2. Get statistic
curl -X GET "http://<>:9200/index-name/_stats?pretty"
3. Delete
curl -X DELETE "http://<>:9200/index-name"
4. Get unique values
curl -X GET "http://<>:9200/index-name/_search" -d '{
"size": 0,
"aggs": {
"langs": {
"terms": {
"field": "<field-name>"
}
}
}
}'
5. Update all documents by query (WHERE <query field name>=<query field value):
curl -X POST http://<>:9200/index-name/_update_by_query -d '{
"script": {
"inline": "ctx._source.<field name>=\"new value\""
},
"query": {
"term": {
"<query field name>": "<query field value>"
}
}
}'
for this action inline script should be enabled:
script.engine.groovy.inline.update: true
script.engine.groovy.indexed.update: true
script.inline: true
in
config/elasticsearch.yml
6. Update field <fieldName> that is missing ("NULL")
curl -X POST http://<host>:9200/<index_name>/_update_by_query -d '{
"script": {
"inline": "ctx._source.<fieldName>=\"newValue\""
},
"query": {
"bool": {
"must_not": {
"exists": {
"field": "<fieldName>"
}
}
}
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment