ElasticSearch#
- class er_evaluation.search.ElasticSearch(base_url, api_key=None)[source]#
Bases:
objectElasticSearch client for user-friendly search queries and aggregation.
Note
The class supports fields with up to one nested level. The use of higher levels of nesting has not yet been tested.
Methods Summary
process_query(user_query, fields[, fuzziness])Process the user's query and build a search query for Elasticsearch.
search(user_query, index, fields[, ...])Perform a search using the user's query on the specified index and fields.
Methods Documentation
- static process_query(user_query, fields, fuzziness=2)[source]#
Process the user’s query and build a search query for Elasticsearch.
- Parameters:
user_query – The user’s query string.
fields – A list of fields to search in.
fuzziness – The fuzziness level for matching (optional, default: 2).
- Returns:
A dictionary representing the Elasticsearch search query.
- search(user_query, index, fields, fuzziness=2, size=10000, agg_fields=None, agg_size=10000, agg_source=None, agg_source_top_hits=5, source=None, timeout=5, max_retries=1)[source]#
Perform a search using the user’s query on the specified index and fields.
- Parameters:
user_query – The user’s query string.
index – The index to search in.
fields – A list of fields to search in.
fuzziness – The fuzziness level for matching (optional, default: 2).
agg_fields – A list of fields to aggregate on (optional).
agg_size – The maximum number of aggregation results to return (optional, default: 10000).
agg_source – A list of fields to return for each top hit in the aggregations (optional).
agg_source_top_hits – The number of top hits to include for each bucket in the aggregations (optional, default: 5).
source – A list of fields to include in the response (optional).
timeout – The timeout for the request in seconds (optional, default: 5).
max_retries – The maximum number of retries for the request (optional, default: 1).
- Returns:
A JSON object containing the search results.
- Raises:
HTTPError – If the request fails.