elasticsearch-dsl

Nested SQL select using elasticsearch

拈花ヽ惹草 提交于 2019-12-12 05:40:08
问题 How can I write this in elasticsearch: SELECT avg(sum) FROM ( SELECT sum(rev) as sum FROM table GROUP BY user_id ) 回答1: If ES version you are using is 2.x use Avg Bucket Aggregation { "aggs": { "group_by_user": { "terms": { "field": "userId" }, "aggs": { "rev_sum": { "sum": { "field": "rev" } } } }, "avg_monthly_sales": { "avg_bucket": { "buckets_path": "group_by_user>rev_sum" } } } } Hope it helps 来源: https://stackoverflow.com/questions/36539447/nested-sql-select-using-elasticsearch

Elastic search query find exact match of values in the list from regexp input parameter

亡梦爱人 提交于 2019-12-11 14:49:42
问题 My data looks like below: { "name": "name1", "name_gr": ["gr1","gr2"] }, { "name": "name2", "name_gr": ["gr1","gr2"] }, { "name": "name3", "name_gr": ["gr2","gr3"] }, { "name": "name4", "name_gr": ["gr1","gr2","gr3","gr4"] }, { "name": "name4", "name_gr": ["gr4","gr5"] } Now, i am trying to write elastic search query using elasticsearch_dsl python module by importing Q from it. My input query will be some regex on "name_gr" . For eg: "name_gr": "gr[12]" . So, in this case I want all the names

elasticsearch-dsl-py Sorting by Text() field

删除回忆录丶 提交于 2019-12-11 13:24:55
问题 I have problem with .sort() method. For example I have Index with Text() field: FILTER = token_filter( 'FILTER', 'edge_ngram', min_gram=3, max_gram=40) ANALYZER = analyzer( 'ANALYZER', tokenizer='standard', type='custom', filter=[ 'standard', 'lowercase', 'stop', 'asciifolding',FILTER]) class Article(DocType): title = Text(analyzer=ANALYZER) body = Text(analyzer='snowball') tags = Keyword() search = Article.search().sort('title') search.execute() when I try to execute search query with sort I

Version conflict when using the delete method of elasticsearch-dsl

做~自己de王妃 提交于 2019-12-11 06:47:32
问题 So, we're using elasticsearch in our Django project, and we're using the elasticsearch-dsl python library. We got the following error in production: ConflictError(409, '{"took":7,"timed_out":false,"total":1,"deleted":0,"batches":1,"version_conflicts":1,"noops":0,"retries":{"bulk":0,"search":0},"throttled_millis":0,"requests_per_second":-1.0,"throttled_until_millis":0,"failures":[{"index":"events","type":"_doc","id":"KJ7SpWsBZnen1jNBRWWM","cause":{"type":"version_conflict_engine_exception",

Python elasticsearch DSL aggregation/metric of nested values per document

筅森魡賤 提交于 2019-12-11 02:39:57
问题 I'm trying to find the minimum (smallest) value in a 2-level nesting (separate minimum value per document). So far I'm able to make an aggregation which counts the min value from all the nested values in my search results but without separation per document. My example schema: class MyExample(DocType): myexample_id = Integer() nested1 = Nested( properties={ 'timestamp': Date(), 'foo': Nested( properties={ 'bar': Float(), } ) } ) nested2 = Nested( multi=False, properties={ 'x': String(), 'y':

ElasticSearch Nested Query - exclude parent document

∥☆過路亽.° 提交于 2019-12-11 02:27:52
问题 Trying to exclude top-level documents where one of the child documents doesn't match the query. For the example below, I'm trying to exclude all documents where one of its nested jobs has current: true , and matches with the company name: Elastic . But since one of the nested job documents matches with current: false and company name: Elastic , this document is returned. I am using a nested query with a must match on company name and a filter where current: false. How can I make it so that

How to enable track_scores in elasticsearch-dsl python

☆樱花仙子☆ 提交于 2019-12-08 04:39:12
问题 I am using elasticsearch dsl to search on elasticsearch : https://elasticsearch-dsl.readthedocs.org/en/latest/ How can i enable track_scores for the query ? I know its supported in elasticsearch: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-sort.html#_track_scores Just dont know how to do the same in Elasticsearch-dsl 回答1: I found this mentioned in the documentation: http://elasticsearch-dsl.readthedocs.org/en/latest/search_dsl.html#extra-properties-and

use existing field as _id using elasticsearch dsl python DocType

﹥>﹥吖頭↗ 提交于 2019-12-07 08:20:06
问题 I have class, where I try to set student_id as _id field in elasticsearch. I am referring persistent example from elasticsearch-dsl docs. from elasticsearch_dsl import DocType, String ELASTICSEARCH_INDEX = 'student_index' class StudentDoc(DocType): ''' Define mapping for Student type ''' student_id = String(required=True) name = String(null_value='') class Meta: # id = student_id index = ELASTICSEARCH_INDEX I tied by setting id in Meta but it not works. I get solution as override save method

How to enable track_scores in elasticsearch-dsl python

浪尽此生 提交于 2019-12-07 08:10:30
I am using elasticsearch dsl to search on elasticsearch : https://elasticsearch-dsl.readthedocs.org/en/latest/ How can i enable track_scores for the query ? I know its supported in elasticsearch: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-sort.html#_track_scores Just dont know how to do the same in Elasticsearch-dsl I found this mentioned in the documentation: http://elasticsearch-dsl.readthedocs.org/en/latest/search_dsl.html#extra-properties-and-parameters s = s.extra(track_scores=True) This worked. 来源: https://stackoverflow.com/questions/33799486/how-to

elasticsearch-dsl aggregations returns only 10 results. How to change this

↘锁芯ラ 提交于 2019-12-07 05:23:36
问题 I am using elasticsearch-dsl python library to connect to elasticsearch and do aggregations. I am following code search.aggs.bucket('per_date', 'terms', field='date')\ .bucket('response_time_percentile', 'percentiles', field='total_time', percents=percentiles, hdr={"number_of_significant_value_digits": 1}) response = search.execute() This works fine but returns only 10 results in response.aggregations.per_ts.buckets I want all the results I have tried one solution with size=0 as mentioned in