How to sort ordinal values in elasticsearch? -


say i've got field 'spicey' possible values 'hot', 'hotter', 'smoking'.

there's intrinsic ordening in these values: they're ordinals.

i'd able sort or filter on them using intrinsic order. example: give me documents spicey > hot.

sure can translate values integers 0,1,2 requires housekeeping on both index , query side i'd rather avoid.

is possible in way? contemplated using multi field mapping not sure if me.

you can sort based on string values scripting sort operation, set each spicey string specific field value.

curl -xget 'http://localhost:9200/yourindex/yourtype/_search' -d  {   "sort": {     "_script": {       "script": "factor.get(doc[\"spicey\"].value)",       "type": "number",       "params": {         "factor": {           "hot": 0,           "hotter": 1,           "smoking": 2         }       },       "order": "asc"     }   } } 

Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -