6

I have a usecase where there are two different types in the same index. Both the types have different structure and mapping.

I need to query both types at the same time using different query DSL.

How can I build my query DSL to simultaneously query more than one type of the same index.

I looked into elasticsearch guide at https://www.elastic.co/guide/en/elasticsearch/guide/current/multi-index-multi-type.html but there is no proper explanation here. According to this even if I set two different types in my request :

/index/type1,type2/_search

I will have to send the same query DSL.

1 Answer 1

9

You need to use multi-search API and the _msearch endpoint

curl -XGET localhost:9200/index/_msearch -d '
{"type": "type1"}
{"query" : {"match_all" : {}}, "from" : 0, "size" : 10}
{"type": "type2"}
{"query" : {"match_all" : {}}, "from" : 0, "size" : 10}
'

Note: make sure to separate each line by newlines (including the last line)

You'll get two responses in the same order as the requests

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.