Hi -- I have a query that searches for items in a certain subcategory that should (not must) have been tagged with a certain tag. The items also have a listed_at
field. If the query finds no items that have the desired tags, then it should just return the most recently listed items in the subcategory.
Oh, and I'm using the msearch
method to do a multi-search in the Ruby ElasticModel API.
The query looks like this: https://gist.github.com/biot023/11f12b82fb7df3dee816434f35b8021f
I would expect that this would return the most recently listed items (according to the listed_at
field), because I would expect all items to have the same score: they should all have the correct subcategory ID and they should none of them have the tag in the query ("snow leopard").
However, the items seem to come back in a random order, each having been assigned a seemingly random score. An example of what actually gets returned is this: https://gist.github.com/biot023/9a959631de8527ec9314e2f7ce34e2c7
(Apologies for the massive code dump, I'm not sure what would be relevant or not.)
As you can see, the scoring seems more-or-less random, which means that the listed_at
field does not get to become the field sorted upon, as desired.
For completeness, the mappings of the items are as follows:
mappings do
indexes( :title, type: "string", analyzer: "snowball" )
indexes( :description, type: "string", analyzer: "snowball" )
indexes( :tags, type: "string", index: "not_analyzed" )
indexes( :section_id, type: "integer" )
indexes( :category_id, type: "integer" )
indexes( :subcategory_id, type: "integer" )
indexes( :section, type: "string", index: "not_analyzed" )
indexes( :category, type: "string", index: "not_analyzed" )
indexes( :subcategory, type: "string", index: "not_analyzed" )
indexes( :section_name, type: "string", analyzer: "snowball" )
indexes( :category_name, type: "string", analyzer: "snowball" )
indexes( :subcategory_name, type: "string", analyzer: "snowball" )
indexes( :listed_at, type: "string", index: "not_analyzed" )
indexes( :price, type: "float" )
indexes( :price_range, type: "string", index: "not_analyzed" )
indexes( :price_range_desc, type: "string", index: "not_analyzed" )
indexes( :colour_ids, type: "integer" )
indexes( :material_ids, type: "integer" )
indexes( :created_at, type: "string", index: "not_analyzed" )
end
Could anyone explain how I'm ending up with a random scoring, and maybe explain how I can fix it so that the score stays consistent?
Thankyou for any and all help offered,
Doug.