Search hits used as filter


(Hrachya Yeghishyan) #1

Hi all,

I wonder whether there is a feature in ES that allows to use search hits of an index as filters of a query on a completely different index.
I'll try to describe what i need on an example, in order to be more clear.
Assume I have two indices, called "First"(which contains arbitrary number of fields) and "Second"(containing only 1 field). Then I perform a search on the only field of the index "Second" and get some hits.
Is there a way to use those hits as filters on a query performed on the index "First"?
Please note that the field values are similar: i.e. there will be no issue related to the field values.


(Ayush Mathur) #2

Hi,
I believe it's not possible via ES UI, i.e. Kibana. Although you can try with curl command to get the desired result.


(Hrachya Yeghishyan) #3

Thanks for the reply @Ayush_Mathur,
actually that is what I'm interested in. I'm working with the Java API for ElasticSearch. And in case of knowing the way to do that with curl, I'll be able to easily apply it in my project as well.


(Ayush Mathur) #4

Try something like:

curl -s -XGET --user "$USER:$PASS" "$ES/$INDEX/_search?pretty" -H "Content-Type: application/json"
--data '{ "query": { "bool": { "must": [ { "match": { "field": "value" } }, { "range" : { "field": { "lte": "value", "gte": "value" } } } ] } }, "size" : 10000, "_source": [ "field list goes here" ] }'

For multiple indices, may be you can omit $INDEX and use --data '{"indices" : ["index1", "index2"], "query"..... (haven't tried this though)

(fix the brackets and indentation :slight_smile: )


(system) #5

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