0

Say I have index like this:

{"id": "12345678", "start": 1541999620214, "end": 1541999620222 }

How do I query for documents with end-start > 10? and now-start < 60000

1 Answer 1

1

Simply like this:

{
  "query": {
    "script": {
      "script": {
        "source": "doc.end.value - doc.start.value < 10"
      }
    }
  }
}

and

{
  "query": {
    "script": {
      "script": {
        "source": "System.currentTimeMillis() - doc.start.value < 60000"
      }
    }
  }
}

As a performance optimization, though, you could store the end - start information inside your document at indexing time so you don't have to resort to scripting and your query would simply become:

{
  "query": {
    "range": {
      "diff": {
        "lt": 10
      }
    }
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.