python 2.7 - How can I use scan/scroll with pagination and sort in ElasticSearch? -


i have es db storing history records process run every day. because want show 20 records per page in history (order date), using pagination (size + from_) combined scroll, worked fine. when wanted used sort in query didn't work. found scroll sort don't work. looking alternative tried es helper scan works fine scrolling , sorting results, solution pagination doesn't seem work, don't understand why since api says scan sends parameters underlying search function. question if there method combine 3 options.

thanks,

ruben

yes, can combine scroll sort, but, when can sort string, need change mapping works fine, documentation here

in order sort on string field, field should contain 1 term only: whole not_analyzed string. of course still need field analyzed in order able query full text.

the naive approach indexing same string in 2 ways include 2 separate fields in document: 1 analyzed searching, , 1 not_analyzed sorting.

"tweet": {      "type":     "string",     "analyzer": "english",     "fields": {         "raw": {              "type":  "string",             "index": "not_analyzed"         }     } } 
  • the main tweet field same before: analyzed full-text field.
  • the new tweet.raw subfield not_analyzed.

now, or @ least have reindexed our data, can use tweet field search , tweet.raw field sorting:

get /_search     {         "query": {             "match": {                 "tweet": "elasticsearch"             }         },         "sort": "tweet.raw"     } 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -