Skip to content

Instantly share code, notes, and snippets.

@sarmiena
Last active December 17, 2015 15:19
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 sarmiena/d945848fd683f39d212c to your computer and use it in GitHub Desktop.
Save sarmiena/d945848fd683f39d212c to your computer and use it in GitHub Desktop.
## Problem
elasticsearch sorting while using "size" and "from" not returning expected results after update
## Create some records (using Ruby to create 100 records)
(1).upto(100) do |i|
`curl -XPUT 'http://localhost:9200/twitter/tweet/#{i}' -d '{ "user" : "#{i}"}'`
end
## View initial search/sort results
curl -X GET 'http://localhost:9200/twitter/tweet/_search?pretty' -d '
{
"sort": [
{
"user": "asc"
}
],
"size": 10,
"from": 0
}
'
{
"took" : 3,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 100,
"max_score" : null,
"hits" : [ {
"_index" : "twitter",
"_type" : "tweet",
"_id" : "1",
"_score" : null, "_source" : { "user" : "1"},
"sort" : [ "1" ]
}, {
"_index" : "twitter",
"_type" : "tweet",
"_id" : "10",
"_score" : null, "_source" : { "user" : "10"},
"sort" : [ "10" ]
}, {
"_index" : "twitter",
"_type" : "tweet",
"_id" : "100",
"_score" : null, "_source" : { "user" : "100"},
"sort" : [ "100" ]
}, {
"_index" : "twitter",
"_type" : "tweet",
"_id" : "11",
"_score" : null, "_source" : { "user" : "11"},
"sort" : [ "11" ]
}, {
"_index" : "twitter",
"_type" : "tweet",
"_id" : "12",
"_score" : null, "_source" : { "user" : "12"},
"sort" : [ "12" ]
}, {
"_index" : "twitter",
"_type" : "tweet",
"_id" : "13",
"_score" : null, "_source" : { "user" : "13"},
"sort" : [ "13" ]
}, {
"_index" : "twitter",
"_type" : "tweet",
"_id" : "14",
"_score" : null, "_source" : { "user" : "14"},
"sort" : [ "14" ]
}, {
"_index" : "twitter",
"_type" : "tweet",
"_id" : "15",
"_score" : null, "_source" : { "user" : "15"},
"sort" : [ "15" ]
}, {
"_index" : "twitter",
"_type" : "tweet",
"_id" : "16",
"_score" : null, "_source" : { "user" : "16"},
"sort" : [ "16" ]
}, {
"_index" : "twitter",
"_type" : "tweet",
"_id" : "17",
"_score" : null, "_source" : { "user" : "17"},
"sort" : [ "17" ]
} ]
}
## Now let's update the first record (notice there is no change, just updating the version)
curl -X POST "http://localhost:9200/twitter/tweet/1" -d '
{"user":"1"}
'
## And... for the problem (notice that previous first record is now missing)
curl -X GET 'http://localhost:9200/twitter/tweet/_search?pretty' -d '
{
"sort": [
{
"user": "asc"
}
],
"size": 10,
"from": 0
}
'
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 100,
"max_score" : null,
"hits" : [ {
"_index" : "twitter",
"_type" : "tweet",
"_id" : "10",
"_score" : null, "_source" : { "user" : "10"},
"sort" : [ "10" ]
}, {
"_index" : "twitter",
"_type" : "tweet",
"_id" : "100",
"_score" : null, "_source" : { "user" : "100"},
"sort" : [ "100" ]
}, {
"_index" : "twitter",
"_type" : "tweet",
"_id" : "11",
"_score" : null, "_source" : { "user" : "11"},
"sort" : [ "11" ]
}, {
"_index" : "twitter",
"_type" : "tweet",
"_id" : "12",
"_score" : null, "_source" : { "user" : "12"},
"sort" : [ "12" ]
}, {
"_index" : "twitter",
"_type" : "tweet",
"_id" : "13",
"_score" : null, "_source" : { "user" : "13"},
"sort" : [ "13" ]
}, {
"_index" : "twitter",
"_type" : "tweet",
"_id" : "14",
"_score" : null, "_source" : { "user" : "14"},
"sort" : [ "14" ]
}, {
"_index" : "twitter",
"_type" : "tweet",
"_id" : "15",
"_score" : null, "_source" : { "user" : "15"},
"sort" : [ "15" ]
}, {
"_index" : "twitter",
"_type" : "tweet",
"_id" : "16",
"_score" : null, "_source" : { "user" : "16"},
"sort" : [ "16" ]
}, {
"_index" : "twitter",
"_type" : "tweet",
"_id" : "17",
"_score" : null, "_source" : { "user" : "17"},
"sort" : [ "17" ]
}, {
"_index" : "twitter",
"_type" : "tweet",
"_id" : "18",
"_score" : null, "_source" : { "user" : "18"},
"sort" : [ "18" ]
} ]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment