I need to search multiple indexes on Elasticsearch,
My problem is that on each index I have the same field name (is_active), how do I specify that it's the field of the other index ?
GET index-1,index-2/_search
{
"query":{
"bool":{
"must":[
{"term":{
"index-1.is_active":true
}},
{"term":{
"index-2.is_active":false
}},
]
}
}
}
Thanks.
eMitch
(Eddie Mitchell)
June 26, 2023, 3:46am
2
Hey @stephane_chan -
You could specify _index
as a term in your query/filter.
something like this?
GET my-index-1,my-index-2/_search
{
"size": 50,
"from": 0,
"query": {
"bool": {
"should": [
{
"bool": {
"must": [
{
"term": {
"is_active": true
}
},
{
"term": {
"_index": "my-index-1"
}
}
]
}
},
{
"bool": {
"must": [
{
"term": {
"is_active": false
}
},
{
"term": {
"_index": "my-index-2"
}
}
]
}
}
]
}
}
}
Results:
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 2,
"successful": 2,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 4,
"relation": "eq"
},
"max_score": 1.6931472,
"hits": [
{
"_index": "my-index-1",
"_id": "mNXG9YgB84P7eKizzU3R",
"_score": 1.6931472,
"_source": {
"is_active": true
}
},
{
"_index": "my-index-1",
"_id": "gtXM9YgB84P7eKizu1n8",
"_score": 1.6931472,
"_source": {
"is_active": true
}
},
{
"_index": "my-index-2",
"_id": "3tXG9YgB84P7eKiz7U1y",
"_score": 1.6931472,
"_source": {
"is_active": false
}
},
{
"_index": "my-index-2",
"_id": "DNXN9YgB84P7eKizfVsk",
"_score": 1.6931472,
"_source": {
"is_active": false
}
}
]
}
}
system
(system)
Closed
July 24, 2023, 3:47am
3
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.