On: September 10, 2017
Some commands in elasticsearch
These are some popular basic commands used in elasticsearch
Create index and import data
# To delete old index, create new index and import in one command:
rake environment elasticsearch:import:model CLASS='Post' FORCE=y
# Just import and update data elasticseach
rake environment elasticsearch:import:model CLASS='Post'
Create and delete index or alias
curl -XPUT 'localhost:9200/new_index?pretty'
curl -XDELETE 'localhost:9200/exist_index?pretty'
Remove many indexs same time
curl -XPOST localhost:9200/_aliases?pretty -d '
{
"actions" : [
{ "remove_index": { "index": "my_index_1" } },
{ "remove_index": { "index": "my_index_2" } },
]
}'
View all aliases and indexes
curl -XGET 'localhost:9200/_alias?pretty'
View data size of indexes
curl -XPGET 'localhost:9200/_cat/indices?pretty'
or
curl -XGET 'localhost:9200/_cat/indices?v&pretty'
yellow open posts_v3 RHypNTRkTmGdJ3wciYvdqw 5 1 11484 0 1001.6kb 1001.6kb
yellow open users_v1 JIMJJCFxT8KHpQvLYzmaKQ 5 1 286 2 65.3kb 65.3kb
yellow open users_v2 ri6_FbGRTQGyvt5it1xA1Q 5 1 0 0 650b 650b
yellow open posts_v1 RcDU2fabRRGhydXwpQ76ag 5 1 11484 0 1mb 1mb
yellow open users M1HXfEcERkia8PgL-N6vcQ 5 1 0 0 650b 650b
View cluster size
curl -XGET 'http://localhost:9200/_cluster/stats?human&pretty'
View index size + info
curl -XGET 'http://localhost:9200/posts/_stats&pretty'
Tagged with rails