Skip to content

Instantly share code, notes, and snippets.

Created August 11, 2012 13:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/cddfb815bde791c00857 to your computer and use it in GitHub Desktop.
Save anonymous/cddfb815bde791c00857 to your computer and use it in GitHub Desktop.
Index aliases vs search
curl -XDELETE 'http://localhost:9200/test'
curl -XPOST 'http://localhost:9200/test' -d '{"settings":{"index":{"number_of_shards":30,"number_of_replicas":1}}}'
curl -XPOST 'http://localhost:9200/_aliases' -d '{"actions":[{"add":{"index":"test","alias":"1","filter":{"term":{"user":1}},"routing":"1"}}]}'
curl -XPOST 'http://localhost:9200/1/documents/doc1' -d '{"user":1,"data":"sample data"}'
curl -XPOST 'http://localhost:9200/1/documents/doc2' -d '{"user":1,"data":"sample data 2"}'
// Does not work:
curl -XPOST 'http://localhost:9200/1/_search?pretty=1'
{
"took" : 5,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"failed" : 0
},
"hits" : {
"total" : 0,
"max_score" : null,
"hits" : [ ]
}
}
// Works:
curl -XPOST 'http://localhost:9200/test/_search?pretty=1'
{
"took" : 11,
"timed_out" : false,
"_shards" : {
"total" : 30,
"successful" : 30,
"failed" : 0
},
"hits" : {
"total" : 2,
"max_score" : 1.0,
"hits" : [ {
"_index" : "test",
"_type" : "documents",
"_id" : "doc1",
"_score" : 1.0, "_source" : {"user":1,"data":"sample data"}
}, {
"_index" : "test",
"_type" : "documents",
"_id" : "doc2",
"_score" : 1.0, "_source" : {"user":1,"data":"sample data 2"}
} ]
}
}
// But, this works:
curl -XPOST 'http://localhost:9200/_aliases' -d '{"actions":[{"remove":{"index":"test","alias":"1"}}]}'
curl -XPOST 'http://localhost:9200/_aliases' -d '{"actions":[{"add":{"index":"test","alias":"1","filter":{"term":{"user":1}},"routing":"1"}}]}'
curl -XPOST 'http://localhost:9200/1/_search?pretty=1'
{
"took" : 153,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"failed" : 0
},
"hits" : {
"total" : 2,
"max_score" : 1.0,
"hits" : [ {
"_index" : "test",
"_type" : "documents",
"_id" : "doc1",
"_score" : 1.0, "_source" : {"user":1,"data":"sample data"}
}, {
"_index" : "test",
"_type" : "documents",
"_id" : "doc2",
"_score" : 1.0, "_source" : {"user":1,"data":"sample data 2"}
} ]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment