-
-
Save sarmiena/d945848fd683f39d212c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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