Hi,
I just got the rails app with fresh database.
After done the migration and the reindex all the things.
And i run the rails app, it gave me this error.
Searchkick::InvalidQueryError - [400] {"error":"SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[JVjzcssRRdiAXRUVUG9cOQ][recipes_development_20150526214612656][0]: SearchParseException[[recipes_development_20150526214612656][0]: query[ConstantScore(*:*)],from[0],size[12]: Parse Failure [Failed to parse source [{\"query\":{\"match_all\":{}},\"size\":12,\"from\":0,\"sort\":[{\"published_at\":\"desc\"}],\"filter\":{\"and\":[{\"range\":{\"published_at\":{\"to\":\"2015-05-26T21:46:29.947+08:00\",\"include_upper\":false}}},{\"term\":{\"language\":\"my\"}}]},\"fields\":[]}]]]; nested: SearchParseException[[recipes_development_20150526214612656][0]: query[ConstantScore(*:*)],from[0],size[12]: Parse Failure [No mapping found for [published_at] in order to sort on]]; }{[JVjzcssRRdiAXRUVUG9cOQ][recipes_development_20150526214612656][1]: SearchParseException[[recipes_development_20150526214612656][1]: query[ConstantScore(*:*)],from[0],size[12]: Parse Failure [Failed to parse source [{\"query\":{\"match_all\":{}},\"size\":12,\"from\":0,\"sort\":[{\"published_at\":\"desc\"}],\"filter\":{\"and\":[{\"range\":{\"published_at\":{\"to\":\"2015-05-26T21:46:29.947+08:00\",\"include_upper\":false}}},{\"term\":{\"language\":\"my\"}}]},\"fields\":[]}]]]; nested: SearchParseException[[recipes_development_20150526214612656][1]: query[ConstantScore(*:*)],from[0],size[12]: Parse Failure [No mapping found for [published_at] in order to sort on]]; }{[JVjzcssRRdiAXRUVUG9cOQ][recipes_development_20150526214612656][2]: SearchParseException[[recipes_development_20150526214612656][2]: query[ConstantScore(*:*)],from[0],size[12]: Parse Failure [Failed to parse source [{\"query\":{\"match_all\":{}},\"size\":12,\"from\":0,\"sort\":[{\"published_at\":\"desc\"}],\"filter\":{\"and\":[{\"range\":{\"published_at\":{\"to\":\"2015-05-26T21:46:29.947+08:00\",\"include_upper\":false}}},{\"term\":{\"language\":\"my\"}}]},\"fields\":[]}]]]; nested: SearchParseException[[recipes_development_20150526214612656][2]: query[ConstantScore(*:*)],from[0],size[12]: Parse Failure [No mapping found for [published_at] in order to sort on]]; }{[JVjzcssRRdiAXRUVUG9cOQ][recipes_development_20150526214612656][3]: SearchParseException[[recipes_development_20150526214612656][3]: query[ConstantScore(*:*)],from[0],size[12]: Parse Failure [Failed to parse source [{\"query\":{\"match_all\":{}},\"size\":12,\"from\":0,\"sort\":[{\"published_at\":\"desc\"}],\"filter\":{\"and\":[{\"range\":{\"published_at\":{\"to\":\"2015-05-26T21:46:29.947+08:00\",\"include_upper\":false}}},{\"term\":{\"language\":\"my\"}}]},\"fields\":[]}]]]; nested: SearchParseException[[recipes_development_20150526214612656][3]: query[ConstantScore(*:*)],from[0],size[12]: Parse Failure [No mapping found for [published_at] in order to sort on]]; }{[JVjzcssRRdiAXRUVUG9cOQ][recipes_development_20150526214612656][4]: SearchParseException[[recipes_development_20150526214612656][4]: query[ConstantScore(*:*)],from[0],size[12]: Parse Failure [Failed to parse source [{\"query\":{\"match_all\":{}},\"size\":12,\"from\":0,\"sort\":[{\"published_at\":\"desc\"}],\"filter\":{\"and\":[{\"range\":{\"published_at\":{\"to\":\"2015-05-26T21:46:29.947+08:00\",\"include_upper\":false}}},{\"term\":{\"language\":\"my\"}}]},\"fields\":[]}]]]; nested: SearchParseException[[recipes_development_20150526214612656][4]: query[ConstantScore(*:*)],from[0],size[12]: Parse Failure [No mapping found for [published_at] in order to sort on]]; }]","status":400}:
This is my code on the controller:
@recipes = Recipe.search '*',
where: {
:published_at => {lt: Time.now},
:language => params[:locale]
},
order: [
{:published_at=>"desc"}
],
page: params[:page],
per_page: 12
Is this happening because the database is still fresh? How to prevent this kind of issue?
Thanks
https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-sort.html
See the unmapped_type option.
Question, how do i translate the sort into the searchkick format?
Should be sort and the order under the sort ?
Thank you very very much for your time to replying. Really appreciate it
Searchkick takes the same format as Elasticsearch's sort option. Here's an example:
Product.search("*", order: [{published_at: {order: "desc", ignore_unmapped: true}}]
Still getting the same error:
Parse Failure [No mapping found for [date] in order to sort on]]; }]","status":400}):
with
order: {date: :desc, unmapped_type: true}
This could be because Rails dates ( Sat, 21 Nov 2015 19:51:04 UTC +00:00) are not in the default mapping types? I'm using Bonsai's ES service. I think this could also depend on the ES version we are running.
ES dateTime mappers are defined here
https://www.elastic.co/guide/en/elasticsearch/reference/1.7/mapping-date-format.html
I will use a custom mapper and re-index with reformatted dates, and will report back with my findings :)
@milankubin try:
order: [{ date: { order: :desc, ignore_unmapped: true}}]
If using Elasticsearch 5 or above change ignore_unmapped: true to unmapped_type: :long
Thanks @PoslinskiNet and @DanAndreasson for helping with this one.
Most helpful comment
If using Elasticsearch 5 or above change
ignore_unmapped: truetounmapped_type: :long