When I use the same script as a scripted field in Kibana I get a Courier fetch: 2 of 17 shards failed. error in Discover and no data. I'm running both in the same cloud.elastic.co hosted version 6.3.1 cluster.
Hi Steven, have you taken a look at your Elasticsearch logs to learn more about the failure?
One thing which is important to note is that two searches you're referencing are different. When you search in ES you're hitting the _search endpoint, you're searching a single index, and you're restricting the response to the values created by your scripted fields. When you search in Discover, you're hitting _msearch endpoint, you're searching with an index pattern across all matching indices, and you're getting back a response containing all of the fields within those indices. I'm not an ES guru, but if you can tell me what your ES logs say then I can rope in some colleagues to help.
GET cart-/_msearch
{}
{"script_fields": {"myfield": {"script": {"source": "float balance; if (doc['arrival_date'] != null && doc['balance_owing'] != null) { long then = doc['arrival_date'].value.getMillis(); long now = new Date().getTime(); long days_old = (now - then) / (1000606024); if (days_old < 30) { balance = doc['balance_owing'].value; } } return balance;"}}}}
The logs say only this and the snapshot INFO messages:
Jul 18, 2018, 5:39:55 AM UTC [2018-07-18T05:39:55,396][WARN][org.elasticsearch.deprecation.common.ParseField] Deprecated field [inline] used, expected [source] instead
I was able resolve my problem by removing references to the data type float. This script works in Kibana:
long then = doc['arrival_date'].value.getMillis(); long now = new Date().getTime(); long age = (now - then) / (1000 * 60 * 60 * 24); if (age < 30) { return doc['balance_owing'].value }
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.