elasticsearch-dsl

ElasticSearch 2.x exists filter for nested field doesn't work

匆匆过客 提交于 2019-12-24 08:50:02
问题 I have the following mapping { "properties": { "restaurant_name": {"type": "string"}, "menu": { "type": "nested", "properties": { "name": {"type": "string"} } } } } I am trying to filter all those documents which have optional "menu" field exists GET /restaurnats/_search { "filter": { "query": { "bool": { "must": [ {"exists" : { "field" : "menu" }} ] } } } } But, when I try the same query to filter those documents which have "restaurant_name", then it works fine. So why nested field check

elasticsearch_dsl: Generate multiple buckets in aggregation

痴心易碎 提交于 2019-12-23 02:49:09
问题 I want to generate this: GET /packets-2017-09-25/_search { "size": 0, "query": { "match": { "transport_protocol": "tcp" } }, "aggs": { "clients": { "terms": { "field": "layers.ip.src.keyword", "size": 1000, "order":{ "num_servers.value":"desc" } }, "aggs": { "num_servers": { "cardinality": { "field": "layers.ip.dst.keyword", "precision_threshold" : 40000 } }, "server_list": { "terms": { "field": "layers.ip.dst.keyword" } } } } } } i.e I want two buckets (num_servers) and (server_list) under

Needs to return only the matched nested objects with full parent body in Elasticsearch

依然范特西╮ 提交于 2019-12-22 00:24:18
问题 I am using Elastic search version 1.7 in my project. I have a an index named colleges and under this index there is a nested index name courses like this. { "name": "College Name" "university": "University Name", "city": 429, "city_name": "London", "state": 328, "state_name": "London", "courses": [ { "id": 26, "degree_name": "Master Of Technology", "annual_fee": 100000, "stream": "Engineering", "degree_id": 9419 }, { "id": 28, "degree_name": "Master Of Philosophy", "annual_fee": 100000,

how to log or print python elasticsearch-dsl query that gets invoked

丶灬走出姿态 提交于 2019-12-19 09:23:31
问题 I am using elasticsearch-dsl for my python application to query elastic search. To debug what query is actually getting generated by elasticsearch-dsl library, I am unable to log or print the final query that goes to elasticsearch. For example, like to see the request body sent to elasticsearch like this : { "query": { "query_string": { "query": "Dav*", "fields": ["name", "short_code"], "analyze_wildcard": true } } } Tried to bring the elasticsearch log level to TRACE. Even then, unable to

Python elasticsearch-dsl django pagination

时光毁灭记忆、已成空白 提交于 2019-12-19 05:24:16
问题 How can i use django pagination on elasticsearch dsl. My code: query = MultiMatch(query=q, fields=['title', 'body'], fuzziness='AUTO') s = Search(using=elastic_client, index='post').query(query).sort('-created_at') response = s.execute() // this always returns page count 1 paginator = Paginator(response, 100) page = request.GET.get('page') try: posts = paginator.page(page) except PageNotAnInteger: posts = paginator.page(1) except EmptyPage: posts = paginator.page(paginator.num_pages) Any

Fetch only filtered nested objects from index in elasticsearch

你说的曾经没有我的故事 提交于 2019-12-17 10:14:08
问题 I have a document with nested objects, something like this: { "title" : "Title 1", "books": [{ "book_title": "b title 1", "year": 2014 }, { "book_title": "b title 2", "year": 2015 }] } Now I need to filter the books on by title (not book_title) and year (let's say 2014). The output I need will be: { "title" : "Title 1", "books": [{ "book_title": "b title 1", "year": 2014 }] } When I use a nested filter I get all the nested objects even if they don't match. How can I fetch only the matched

How to serialize Django GeoPt for Elasticsearch

牧云@^-^@ 提交于 2019-12-14 03:05:46
问题 How to define GeoPointField() in elasticsearch django. It shows a serialization error when i am trying to save the instance. i am using library "django_elasticsearch_dsl code: from django_elasticsearch_dsl.fields import GeoPointField geolocation = GeoPointField() when i am trying to save the data user = GutitUser.objects.get(phone_number=phone_number) lat, lon = get_lat_long() user.geolocation.lat = lat user.geolocation.lon = lon user.save() it shows error: "Unable to serialize <django_google

Elasticsearch connect range and term to same array item

假如想象 提交于 2019-12-13 22:18:43
问题 I have a user document with a field called experiences which is an array of objects, like: { "experiences": [ { "end_date": "2017-03-02", "is_valid": false }, { "end_date": "2015-03-02", "is_valid": true } ] } With this document I have to search users where end date is in last year and is_valid is true. At this time I have a query -> bool and I add two must there, one range for the end_date and one term for the is_valid . { "query": { "bool": { "must": { "term": { "experiences.is_valid": true

Elasticsearch is not sorting the results

风流意气都作罢 提交于 2019-12-13 12:24:04
问题 I'm having problem with an elasticsearch query. I want to be able to sort the results but elasticsearch is ignoring the sort tag. Here my query: { "sort": [{ "title": {"order": "desc"} }], "query":{ "term": { "title": "pagos" } } } However, when I remove the query part and I send only the sort tag, it works. Can anyone point me out the correct way? I also tried with the following query, which is the complete query that I have: { "sort": [{ "title": {"order": "asc"} }], "query":{ "bool":{

Error when indexing data using elasticsearch dsl

二次信任 提交于 2019-12-13 03:39:02
问题 I have two models which are as follows: class PostUser(models.Model): user_id = models.CharField(max_length=1000,blank=True,null=True) reputation = models.CharField(max_length = 1000 , blank = True , null = True) def __unicode__(self): return self.user_id def indexing(self): obj = PostUserIndex( meta = {'id': self.id}, user_id = self.user_id, reputation = self.reputation, ) obj.save(index = 'post-user-index') return obj.to_dict(include_meta=True) class Posts(models.Model): user_post_id =