To perform multiple condition searches on Elasticsearch indices using curl commands, follow these steps:
-
Construct the JSON Query: Use the bool query in JSON to combine multiple search conditions.
-
Execute the Curl Command: Send the JSON query to the appropriate Elasticsearch endpoint with curl.
Example:
1 2 3 4 5 6 7 8 9 10 11 12 |
curl –X GET “http://localhost:9200/your_index/_search” \ –H ‘Content-Type: application/json’ \ –d ‘{“query”: {“bool”: { “must”: [ { “term”: { “field1”: “value1” } }, { “range”: { “age”: { “gte”: 18, “lte”: 25 } } } ], “filter”: [ { “exists”: { “field”: “status” } } ] }}}’ |
Explanation:
- bool query: Combines multiple conditions using must, must_not, and filter.
- Must Clauses: Conditions that must be satisfied for a document to match.
- Filter Clauses: Conditions that narrow results without affecting scoring.
- curl Command: Sends the JSON query to Elasticsearch.
This approach allows you to perform complex searches across multiple fields in your ES index.