弹性搜索:搜索结果中的pyes.exceptions.IndexMissingException异常

时间:2012-08-29 11:06:37

标签: python full-text-search elasticsearch pyes

这是关于Elastic-Search python API(pyes)的问题。

我通过curl运行一个非常简单的测试用例,一切似乎都按预期工作。

以下是curl测试用例的描述:

ES中唯一存在的文档是:

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

然后我在ES搜索“找到”这个词的所有文件。结果似乎没问题:

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!"}

    } ]
  }
}

然而,当我通过python2.7 api(pyes)运行相同的查询时,出现问题:

>>> 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

如您所见,pyes返回结果对象,但由于某种原因,我甚至无法获得结果数。

有人猜到这里可能有什么问题吗?

提前多多感谢!

1 个答案:

答案 0 :(得分:1)

参数的名称已更改,不再称为index,而是名为indices,它是一个列表:

>>> result = conn.search({"page_text":"found"}, indices=["index1"])