Searchkick: order_by fails when no items in index

Created on 15 May 2014  路  5Comments  路  Source: ankane/searchkick

Pushing code to a clean instance without any items in the index results in stacks. Any way of handling this more gracefully?

No mapping found for [updated_at] in order to sort on

query = Product.search "*", page: params[:page], per_page: 15,
          order: {updated_at: :desc},
          fields: [:name, :description],
          execute: false

@products = query.execute

Most helpful comment

Looks like it's already supported.

Product.search "*", order: {updated_at: {order: "desc", ignore_unmapped: true}}

All 5 comments

Unfortunately, I'm not aware of one. You can specify your own mapping to include updated_at (not ideal), but until a product is indexed that has an updated_at field, Elasticsearch won't have a mapping for it - and Searchkick won't know what your search_data method returns without at least one record.

Found this, There is an option to ignore unmapped fields when sorting:
Allow search to continue when sort field is missing from type mapping

https://github.com/elasticsearch/elasticsearch/issues/1558

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-sort.html

Cool, looks like ES has solved the issue. Just need to make the order option more flexible to support as much as possible of http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-sort.html

Looks like it's already supported.

Product.search "*", order: {updated_at: {order: "desc", ignore_unmapped: true}}

:+1:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gerrywastaken picture gerrywastaken  路  3Comments

jakcharlton picture jakcharlton  路  5Comments

neyp picture neyp  路  3Comments

JensDebergh picture JensDebergh  路  4Comments

cubaraphael picture cubaraphael  路  3Comments