ElasticQuery¶
A simple query builder for Elasticsearch. Install with pip install elasticquery
. Uses metod calls and their args/kwargs to generate query/filter/aggregate objects. Outputs dict/json represntation to be passed directly to ES.
ElasticQuery Client¶
The main ElasticQuery
class allows you to build Elasticsearch queries using a Pythonic
API:
from elasticquery import ElasticQuery, Query, Aggregate
# Create a new query
q = ElasticQuery()
# Match something
q.query(Query.match('some_field', 'some_text'))
# Aggregate something
q.aggregate(Aggregate.terms('my_terms', 'some_field'))
API¶
-
class
elasticquery.elasticquery.
ElasticQuery
(es=None, index=None, doc_type=None)¶ A class for building ES queries.
-
aggregate
(*aggregates)¶ Add one or more aggregates to this query.
-
dict
()¶ Returns the current query in dict format.
-
fields
(fields)¶ Set the fields/_source for this query.
-
from_
(from_)¶ Set the from/offset for this query.
-
get
()¶ Execute the current query (requires _es, _index & _doc_type).
-
json
(**kwargs)¶ Returns a JSON representation of the current query. Kwargs are passed to
json.dumps
.
-
query
(query)¶ Set the query for this query.
-
set
(key, value)¶ Set an arbitrary attribute on this query.
-
size
(size)¶ Set the size of this query.
-
sort
(field, order=None)¶ Sort this query.
-
suggest
(*suggesters)¶ Add one or more suggesters to this query.
-
timeout
(timeout)¶ Set the timeout for this query.
-
Queries¶
Note that all Query calls can also be passed additional keyword arguments not specified here, but no validation of inputs is done on them.
Query.simple_query_string¶
Query.simple_query_string(query, fields=[], default_operator=None, analyzer=None, flags=None, locale=None, lenient=None, lowercase_expanded_terms=None, analyze_wildcard=None, minimum_should_match=None)
Query.span_first¶
Query.span_first(Query)
Query.nested¶
Query.nested(path, Query)
Query.prefix¶
Query.prefix(field, value, boost=None)
Query.function_score¶
Query.function_score([functions], query=Query)
Query.span_near¶
Query.span_near([Query])
Query.script¶
Query.script(None)
Query.match¶
Query.match(field, query, operator=None, zero_terms_query=None, cutoff_frequency=None, boost=None, rewrite=None, prefix_length=None, fuzziness=None, minimum_should_match=None, analyzer=None, max_expansions=None)
Query.type¶
Query.type(value)
Query.span_not¶
Query.span_not(include=Query, exclude=Query)
Query.fuzzy¶
Query.fuzzy(field, value, boost=None, fuzziness=None, prefix_length=None, max_expansions=None)
Query.term¶
Query.term(field, value, boost=None)
Query.geo_distance¶
Query.geo_distance(field, lat=None, lon=None)
Query.span_multi¶
Query.span_multi(Query)
Query.common¶
Query.common(query, minimum_should_match=None, high_freq=None, low_freq=None, high_freq_operator=None, low_freq_operator=None, cutoff_frequency=None)
Query.indices¶
Query.indices([indices], query=Query, no_match_query=Query)
Query.geo_polygon¶
Query.geo_polygon(field, [points])
Query.exists¶
Query.exists(field)
Query.span_containing¶
Query.span_containing(Query, Query)
Query.geohash_cell¶
Query.geohash_cell(field, lat=None, lon=None)
Query.dis_max¶
Query.dis_max([Query])
Query.has_parent¶
Query.has_parent(parent_type, query=Query)
Query.geo_distance_range¶
Query.geo_distance_range(field, lat=None, lon=None)
Query.multi_match¶
Query.multi_match([fields], query, operator=None, zero_terms_query=None, cutoff_frequency=None, boost=None, rewrite=None, prefix_length=None, fuzziness=None, minimum_should_match=None, analyzer=None, max_expansions=None)
Query.more_like_this¶
Query.more_like_this([fields], like_text)
Query.bool¶
Query.bool(must=[Query], must_not=[Query], should=[Query])
Query.template¶
Query.template(None)
Query.limit¶
Query.limit(value)
Query.span_term¶
Query.span_term(field, value, boost=None)
Query.span_or¶
Query.span_or([Query])
Query.terms¶
Query.terms(field, [value])
Query.has_child¶
Query.has_child(type, query=Query)
Query.missing¶
Query.missing(field)
Query.span_within¶
Query.span_within(Query, Query)
Query.boosting¶
Query.boosting(positive=None, negative=None)
Query.geo_shape¶
Query.geo_shape(field, type=None, coordinates=[])
Query.regexp¶
Query.regexp(field, value, boost=None, flags=None)
Query.match_all¶
Query.match_all(boost=None)
Query.geo_bounding_box¶
Query.geo_bounding_box(field, top_left=None, bottom_right=None)
Query.ids¶
Query.ids([values], type=None)
Query.range¶
Query.range(field, gte=None, gt=None, lte=None, lt=None)
Query.wildcard¶
Query.wildcard(field, value, boost=None)
Query.query_string¶
Query.query_string(query, fields=[], default_field=None, default_operator=None, analyzer=None, allow_leading_wildcard=None, lowercase_expanded_terms=None, enable_position_increments=None, fuzzy_max_expansions=None, fuzziness=None, fuzzy_prefix_length=None, phrase_slop=None, boost=None, analyze_wildcard=None, auto_generate_phrase_queries=None, max_determinized_states=None, minimum_should_match=None, lenient=None, locale=None, time_zone=None)
Query.constant_score¶
Query.constant_score(query=Query)
Aggregates¶
Note that all Aggregate calls can also be passed additional keyword arguments not specified here, but no validation of inputs is done on them.
Aggregate.bucket_script¶
Aggregate.bucket_script(name, {})
Aggregate.extended_stats_bucket¶
Aggregate.extended_stats_bucket(name, buckets_path)
Aggregate.global¶
Aggregate.global(name)
Aggregate.nested¶
Aggregate.nested(name, path)
Aggregate.ip_range¶
Aggregate.ip_range(name, field, [ranges])
Aggregate.filters¶
Aggregate.filters(name, [Query])
Aggregate.children¶
Aggregate.children(name, type)
Aggregate.scripted_metric¶
Aggregate.scripted_metric(name)
Aggregate.top_hits¶
Aggregate.top_hits(name)
Aggregate.extended_stats¶
Aggregate.extended_stats(name, field)
Aggregate.value_count¶
Aggregate.value_count(name, field)
Aggregate.date_histogram¶
Aggregate.date_histogram(name, field, interval)
Aggregate.sampler¶
Aggregate.sampler(name, field)
Aggregate.derivative¶
Aggregate.derivative(name, buckets_path)
Aggregate.sum_bucket¶
Aggregate.sum_bucket(name, buckets_path)
Aggregate.max_bucket¶
Aggregate.max_bucket(name, buckets_path)
Aggregate.histogram¶
Aggregate.histogram(name, field, interval)
Aggregate.date_range¶
Aggregate.date_range(name, field, [ranges])
Aggregate.cardinality¶
Aggregate.cardinality(name, field)
Aggregate.geohash_grid¶
Aggregate.geohash_grid(name, field)
Aggregate.geo_distance¶
Aggregate.geo_distance(name, field, origin, [ranges])
Aggregate.bucket_selector¶
Aggregate.bucket_selector(name, {})
Aggregate.percentiles_bucket¶
Aggregate.percentiles_bucket(name, buckets_path)
Aggregate.percentile_ranks¶
Aggregate.percentile_ranks(name, field)
Aggregate.cumulative_sum¶
Aggregate.cumulative_sum(name, buckets_path)
Aggregate.moving_avg¶
Aggregate.moving_avg(name, buckets_path)
Aggregate.geo_bounds¶
Aggregate.geo_bounds(name, field)
Aggregate.stats_bucket¶
Aggregate.stats_bucket(name, buckets_path)
Aggregate.avg_bucket¶
Aggregate.avg_bucket(name, buckets_path)
Aggregate.avg¶
Aggregate.avg(name, field)
Aggregate.stats¶
Aggregate.stats(name, field)
Aggregate.min¶
Aggregate.min(name, field)
Aggregate.sum¶
Aggregate.sum(name, field)
Aggregate.percentiles¶
Aggregate.percentiles(name, field)
Aggregate.min_bucket¶
Aggregate.min_bucket(name, buckets_path)
Aggregate.terms¶
Aggregate.terms(name, field)
Aggregate.missing¶
Aggregate.missing(name, field)
Aggregate.max¶
Aggregate.max(name, field)
Aggregate.geo_centroid¶
Aggregate.geo_centroid(name, field)
Aggregate.serial_diff¶
Aggregate.serial_diff(name, buckets_path)
Aggregate.filter¶
Aggregate.filter(name, Query)
Aggregate.range¶
Aggregate.range(name, field, [ranges])
Aggregate.significant_terms¶
Aggregate.significant_terms(name, field)
Aggregate.reverse_nested¶
Aggregate.reverse_nested(name)
Suggesters¶
Note that all Suggester calls can also be passed additional keyword arguments not specified here, but no validation of inputs is done on them.
Suggester.completion¶
Suggester.completion(field, size=None)
Suggester.phrase¶
Suggester.phrase(field, gram_size=None, real_word_error_likelihood=None, confidence=None, max_errors=None, separator=None, size=None, analyzer=None, shard_size=None, collate=None)
Suggester.term¶
Suggester.term(field, analyzer=None, size=None, sort=None, suggest_mode=None)