Вопрос

This is a question about Elastic-Search python API (pyes).

I run a very simple testcase through curl, and everything seems to work as expected.

Here is the description of the curl test-case:

The only document that exists in the ES is:

curl 'http://localhost:9200/test/index1' -d '{"page_text":"This is the text that was found on the page!"}

Then I search the ES for all documents that the word "found" exists in. The result seems to be OK:

curl 'http://localhost:9200/test/index1/_search?q=page_text:found&pretty=true'
{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 1,
    "max_score" : 0.15342641,
    "hits" : [ {
      "_index" : "test",
      "_type" : "index1",
      "_id" : "uaxRHpQZSpuicawk69Ouwg",
      "_score" : 0.15342641, "_source" : {"page_text":"This is the text that was found on the page!"}

    } ]
  }
}

However, when I run the same query though python2.7 api (pyes), something goes wrong:

>>> import pyes
>>> conn = pyes.ES('localhost:9200')
>>> result = conn.search({"page_text":"found"}, index="index1")
>>> print result
<pyes.es.ResultSet object at 0xd43e50>
>>> result.count()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/pythonbrew/pythons/Python-2.7.3/lib/python2.7/site-packages/pyes/es.py", line 1717, in count
    return self.total
  File "/usr/local/pythonbrew/pythons/Python-2.7.3/lib/python2.7/site-packages/pyes/es.py", line 1686, in total
    self._do_search()
  File "/usr/local/pythonbrew/pythons/Python-2.7.3/lib/python2.7/site-packages/pyes/es.py", line 1646, in _do_search
    doc_types=self.doc_types, **self.query_params)
  File "/usr/local/pythonbrew/pythons/Python-2.7.3/lib/python2.7/site-packages/pyes/es.py", line 1381, in search_raw
    return self._query_call("_search", body, indices, doc_types, **query_params)
  File "/usr/local/pythonbrew/pythons/Python-2.7.3/lib/python2.7/site-packages/pyes/es.py", line 622, in _query_call
    return self._send_request('GET', path, body, params=querystring_args)
  File "/usr/local/pythonbrew/pythons/Python-2.7.3/lib/python2.7/site-packages/pyes/es.py", line 603, in _send_request
    raise_if_error(response.status, decoded)
  File "/usr/local/pythonbrew/pythons/Python-2.7.3/lib/python2.7/site-packages/pyes/convert_errors.py", line 83, in raise_if_error
    raise excClass(msg, status, result, request)
pyes.exceptions.IndexMissingException: [_all] missing

As you can see, pyes returns the result object, but from some reason I can't even get the number of results there.

Anyone was any guess what may be wrong here?

Thanks a lot in advance!

Это было полезно?

Решение

The name of the parameter changed, it's no longer called index, it's called indices and it's a list:

>>> result = conn.search({"page_text":"found"}, indices=["index1"])
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top