Combining Results from Multiple Indices
When executing a multi-index search, Elasticsearch combines results from all specified indices and returns them in a single response.
Example: Multi-Index Search with Combined Results
Let’s search for products and users containing the term “Elasticsearch” and retrieve combined results.
GET /products,users/_search
{
"query": {
"multi_match": {
"query": "Elasticsearch",
"fields": ["name", "description"]
}
}
}
Sample Output:
{
"took": 10,
"hits": {
"total": {
"value": 3,
"relation": "eq"
},
"hits": [
{
"_index": "products",
"_id": "1",
"_source": {
"name": "Elasticsearch Basics",
"description": "Learn the fundamentals of Elasticsearch."
}
},
{
"_index": "users",
"_id": "123",
"_source": {
"name": "John Doe",
"email": "john.doe@example.com"
}
},
{
"_index": "users",
"_id": "456",
"_source": {
"name": "Jane Smith",
"email": "jane.smith@example.com"
}
}
]
}
}
In this output:
- We receive search results from both the products and users indices.
- Each hit includes information about the index (_index), document ID (_id), and relevant source fields (_source).
Elasticsearch Multi Index Search
In Elasticsearch, multi-index search refers to the capability of querying across multiple indices simultaneously. This feature is particularly useful when you have different types of data stored in separate indices and need to search across them in a single query. In this article, we’ll explore what multi-index search is, why it’s important, and how to use it effectively with practical examples.
Contact Us