Sachin Karia
Sachin Karia

Reputation: 565

sorting on a nested object elasticsearch 5.2, error: not of nested type

I have a field (propertyScore) which is in my Property model inside the 'review' object. I would like to sort on this field using elasticsearch sort.

Here is an example of my property:

{
"bedrooms": 2,
"bathrooms": 2,
"review": {
           "propertyScore": 20
         },
}

On my bedrooms field I execute the search query below:

sort: 
   [ '_score',
     { bathrooms: { order: 'desc'} }
]

How would I then sort on the score field under my reviews.

I have currently done:

sort: 
       [ '_score',
         { propertyScore: { order: 'desc', 
                            nested_path: 'review'} 
         } 
       ]

and receive the error:

[query_parsing_exception] [nested] nested object under path [review] is not of nested type

Upvotes: 0

Views: 71

Answers (1)

Ashish Goel
Ashish Goel

Reputation: 919

I believe there is an issue with your mapping. The "review" property is not of type nested. Hence, when using sort with "nested_path" equal to "review", you are getting this error.

You can either change this mapping or you can change the way you are executing the sort. Just try this:

sort: 
 [ '_score',
   { "review.propertyScore": { order: 'desc'} }
 ]

Upvotes: 0

Related Questions