ElasticSearch 2 bucket level sorting -


the mapping of database this:

{    "users": {       "mappings": {          "user": {             "properties": {               credentials": {                   "type": "nested",                   "properties": {                      "achievement_id": {                         "type": "string"                      },                      "percentage_completion": {                         "type": "integer"                      }                   }                },                "current_location": {                   "type": "geo_point"                },              "locations": {                "type": "geo_point"          }             }          }       }    } 

now in mapping, can see there 2 geo-distance fields 1 current_location , other locations. want sort user based on credentials.percentage_completion nested field. work fine example query, example query:

get /users/user/_search?size=23 {   "sort": [     {       "credentials.percentage_completion": {         "order": "desc",         "missing": "_last"       }     },  "_score"   ],   "query": {     "filtered": {       "query": {         "match_all": {}       },       "filter": {         "geo_distance": {           "distance": "100000000km",           "user.locations": {             "lat": 19.77,             "lon": 73           }         }       }     }   } } 

i want change sorting order made buckets, desired order first show people @ 100km radius of user.current_location , sort them according credentials.percentage_completion , rest of users sorted again credentials.percentage_completion.

i tried putting conditional in sorting , made multilevel not work because nested can have filters , on nested fields child only.

i thought can use _score sorting , give more relevance people under 1000 km geo-distance filter, don't seem find way give relevance in filter.

is there missing here , great.

thanks

finally solved it, posting here other can take lead if here. way solve give constant relevance score particular query here geo distance not able use in query, found constant score query: allows wrap filter inside query.

this how query looks:

get /users/user/_search?size=23 {   "sort": [     "_score",     {       "credentials.udacity_percentage_completion": {         "order": "desc",         "missing": "_last"       }     }   ],   "explain": true,   "query": {     "filtered": {       "query": {         "bool": {           "should": [             {               "constant_score": {                 "filter": {                   "geo_distance": {                     "distance": "100km",                     "user.current_location": {                       "lat": 19.77,                       "lon": 73                     }                   }                 },                 "boost": 50               }             },             {               "constant_score": {                 "filter": {                   "geo_distance": {                     "distance": "1000000km",                     "user.locations": {                       "lat": 19.77,                       "lon": 73                     }                   }                 },                 "boost": 1               }             }           ]         }       },       "filter": {         "geo_distance": {           "distance": "10000km",           "user.locations": {             "lat": 19.77,             "lon": 73           }         }       }     }   } } 

Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -