pyelasticsearch

elasticsearch dynamic query - Add another field to each document returned

谁都会走 提交于 2021-02-06 09:26:07
问题 What I need is very simple, but I am unable to find how to do it in Elasticsearch, possibly because of the complexity of what is required to be done. Input (two sample JSON documents) { "car" : 150, "bike" : 300 } { "car" : 100, "bike" : 200} What I want in return is that when I fire a search query it returns me the documents with an extra field inventory which is defined as the sum of number of cars and bikes. And in the sorted order. Sample Output: hits: [ { "car" : 150, "bike" : 300,

haystack.exceptions.MissingDependency: The 'elasticsearch' backend requires the installation of 'elasticsearch'

自古美人都是妖i 提交于 2020-01-03 05:27:10
问题 I am newbie to Django-haystack. I got an error while following Django-Haystack documentation. Command execution order, I followed: I started elasticsearch server (1.7.3) using command prompt and I am able to access http://127.0.0.1:9200/ python manage.py rebuild_index Output: WARNING: This will irreparably remove EVERYTHING from your search index in connection 'default'. Your choices after this are to restore from backups or rebuild via the rebuild_index command. Are you sure you wish to

Elastic search not giving data with big number for page size

落花浮王杯 提交于 2019-12-30 07:42:30
问题 Size of data to get: 20,000 approx Issue: searching Elastic Search indexed data using below command in python but not getting any results back. from pyelasticsearch import ElasticSearch es_repo = ElasticSearch(settings.ES_INDEX_URL) search_results = es_repo.search( query, index=advertiser_name, es_from=_from, size=_size) If I give size less than or equal to 10,000 it works fine but not with 20,000 Please help me find an optimal solution to this. PS: On digging deeper into ES found this

Elastic search Not filter inside and filter

♀尐吖头ヾ 提交于 2019-12-25 02:57:05
问题 I am trying to add a "not" filter inside "and" filter Sample input: { "query":{ "filtered":{ "query":{ "query_string":{ "query":"error", "fields":[ "request" ] } }, "filter":{ and:[ { "terms":{ "hashtag":[ "br2" ] }, "not":{ "terms":{ "hashtag":[ "br1" ] } } } ] } } } }, } But above is giving error, i also tried various combination but in vain. Above is just an example in short i require a query in which both "and", "not" filter are present. 回答1: you forgot the "filters" array. Write it like

Stable Django-Haystack + elasticsearch setup

淺唱寂寞╮ 提交于 2019-12-24 00:39:51
问题 I'm wondering what the best combination of Django-Haystack + elasticsearch + pyelasticsearch/elasticsearch-py is. I've deployed a setup using Haystack 2.1.1-dev + elasticsearch 1.1.1 + elasticsearch-py 1.0 on an Ubuntu 12.04 machine. I tried using Haystack 2.1.0 (latest stable release) with elasticsearch 1.1.1 and pyelasticsearch 0.6.1, but it kept throwing me an error saying Django-Haystack depends on pyelasticsearch; so I switched to 2.1.1-dev, which worked beautifully. But now I'm trying

elasticsearch scrolling using python client

寵の児 提交于 2019-12-22 09:39:02
问题 When scrolling in elasticsearch it is important to provide at each scroll the latest scroll_id : The initial search request and each subsequent scroll request returns a new scroll_id — only the most recent scroll_id should be used. The following example (taken from here) puzzle me. First, the srolling initialization: rs = es.search(index=['tweets-2014-04-12','tweets-2014-04-13'], scroll='10s', search_type='scan', size=100, preference='_primary_first', body={ "fields" : ["created_at",

Elasticsearch Aggregation by Day of Week and Hour of Day

十年热恋 提交于 2019-12-06 07:04:34
I have documents of type: [{"msg":"hello", date: "some-date"},{"msg":"hi!", date: "some-date"}, ... I want to have the count of documents by day of week. For example x messages were sent on Monday and y were sent on Tuesday and so on. I have used date_histogram with aggregation but it returns me the documents day wise. It does return me the day, but say "Wed, 22" and "Wed, 29" are returned as separate aggregation documents. This is somewhat related to Elasticsearch - group by day of week and hour but there is no answer to that question so I am reposting it. According to the suggestion there it

elasticsearch scrolling using python client

泄露秘密 提交于 2019-12-05 22:31:53
When scrolling in elasticsearch it is important to provide at each scroll the latest scroll_id : The initial search request and each subsequent scroll request returns a new scroll_id — only the most recent scroll_id should be used. The following example (taken from here ) puzzle me. First, the srolling initialization: rs = es.search(index=['tweets-2014-04-12','tweets-2014-04-13'], scroll='10s', search_type='scan', size=100, preference='_primary_first', body={ "fields" : ["created_at", "entities.urls.expanded_url", "user.id_str"], "query" : { "wildcard" : { "entities.urls.expanded_url" : "*.ru"

Format the output of elasticsearch-py

微笑、不失礼 提交于 2019-12-04 03:30:27
问题 I'm trying to use the python client for elasticsearch . Here is a minimal example: import logging logging.basicConfig() from elasticsearch import Elasticsearch as ES print "Setup connection..." es=ES(['localhost:8080']) print "Done!" print "Count number of users..." print es.count(index='users') The output is: {u'count': 836780, u'_shards': {u'successful': 5, u'failed': 0, u'total': 5}} I have two questions: How do I get rid of the u' ( u followed by a single quote )? How can I extract the

How to have Range and Match query in one elastic search query using python?

别说谁变了你拦得住时间么 提交于 2019-12-02 10:19:11
问题 I have to find the matching documents which have the string, for example: "sky", within some "key" range. When I write separate match and range query, I get the output from the ES but it throws an exception when merged together. range query: res = es.search(index="dummy", body={"from":0, "size":0,"query": {"range":{"key":{"gte":"1000"}}}}) match query: res = es.search(index="dummy", body={"from":0, "size":0,"query": {"match":{"word":"sky"}}}) combined query: res = es.search(index="dummy",