How to exclude records in between two records in elasticsearch?


(Patrick Ian) #1

Let's say I have 10 documents in an index. document 2 has the k-v pair:
'activity': 'start' and document 8 has 'activity':'end'. I want to exclude all documents between and including documents 2 and 8. How can I do this in elasticsearch?


(David Pilato) #2

I don't think there is an easy way to do that.
I believe you need to think about your model in a different way and basically solve that problem at index time instead.


(Patrick Ian) #3

If it helps, these documents have a timestamp field. Is there a way to get the timestamp of document 2 and document 8 and use it in a range filter (in a single query)?

What I had in mind requires more complex steps. I'd first query the timestamps of the 2 documents, then do another query that has a range filter.


(David Pilato) #4

Is there a way to get the timestamp of document 2 and document 8 and use it in a range filter (in a single query)?

I don't think so.


(Patrick Ian) #5

I'll have to do 2 separate queries then?


(David Pilato) #6

May be. Probably.

I don't exactly know the use case. I mean what problem you are trying to solve.
You always wrote things about how you want to solve it, the HOW. Not the WHAT.

As I said, I think you should may be "solve that problem at index time instead."

In case it helps, there is the Multi Search API: https://www.elastic.co/guide/en/elasticsearch/reference/5.5/search-multi-search.html

But you can't take the result of a first query as the input of the second one.


(system) #7

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.