2

I have two fields one is timestamp which is associated with every record and one is expiryDate so I want to put a lucene query in the discover part search section such that it extract out the records for which expiry date > timestamp. Can anyone help me in writing the query. Consider online.timestamp as one field and online.expiry as another field.

agrawal1084
  • 129
  • 2
  • 11

1 Answers1

2

You can write the below query:-

{"constant_score":{"filter":{"script" : { "script" : "doc['online.expiry'].value > doc['online.timestamp'].value"}}}}

You may see an error while using above query such as:-

ScriptException[scripts of type [inline], operation [search] and lang [groovy] are disabled]

To solve this error, edit your elasticsearch.yml file and enter the following property at the end:-

 script.inline:on

Then you can restart your Elasticsearch node or cluster and then query the same on Kibana which will fetch you desired records.

Yuvraj Gupta
  • 2,475
  • 16
  • 26
  • where should I apply the above query? I applied in script field but it throws `Failed to parse expression` – Bilal Usean Dec 08 '16 at 06:55
  • Hi @BilalUsean You should mention the query in Kibana search bar. You would require to mention script.inline:on in elasticsearch.yml file. – Yuvraj Gupta Dec 09 '16 at 08:25