0

I have the following working query, using CURL:

  curl -X GET 'http://myhost/myindex/_search?q=text:%7B1933%20TO%201949%7D'

which identifies all documents inside the index myindex which in the text field (string type) contains mentions of dates between 1933 and 1949. I would like to use this query programatically from Python, and in this sense I have the Python ElasticSearch client installed, Pyes:

  from elasticsearch import ElasticSearch
  from pyes import *

and then I would like to call

  es = ElasticSearch('myhost')
  totalDocs = es.search('myindex', body={'query':{'query_string':{'query': 'text:%7B1933%20TO%201949%7D'}},"size":0})['hits']['total']

but this syntax is not working. Also it is important that I look into the text field only for these date mentions. Are there any ways to use the initial query in Python? Many thanks!

Later edit: I have also tried it like this:

  totalDocs = es.search('myindex', 'text:%7B1933%20TO%201949%7D')['hits']['total']

It works, but it returns no documents at all.

Actually my question resumes to this question: [ElasticSearch - specify range for a string field

3
  • What result do you get? Is there an error message?
    – rlms
    Dec 30, 2014 at 14:40
  • It doesn't crash but it doesn't return anything. I know for sure that there should be more than 100,000 documents that fulfill this condition in my index.
    – Crista23
    Dec 30, 2014 at 15:02
  • Would you please add your document's format? Jun 25, 2020 at 22:22

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.