So, I have myindex
elastic search index with two types type1
and type2
. Both the type has two common fields as name
and description
as below:
{
"name": "",
"description": ""
}
I want 5 results from type1
and 5 results from result2
if I specify the size as 10 in a single search query?
The below query gives me 10 results from type1
if the matching results are more from type1
:
curl -XPOST 'localhost:9200/myindex/_search?pretty&pretty' -H 'Content-Type: application/json' -d'
{
"size": 10,
"query": {
"match": {
"name": "xyz"
}
}
}'
I can do this in two different queries as below, but I want to do it in one go.
curl -XPOST 'localhost:9200/myindex/type1/_search?pretty&pretty' -H 'Content-Type: application/json' -d'
{
"size": 5,
"query": {
"match": {
"name": "xyz"
}
}
}'
curl -XPOST 'localhost:9200/myindex/type2/_search?pretty&pretty' -H 'Content-Type: application/json' -d'
{
"size": 5,
"query": {
"match": {
"name": "xyz"
}
}
}'