使用弹性搜索时的HTTP_EXCEPTIONS

时间:2016-11-30 00:27:43

标签: python elasticsearch

我在使用弹性搜索运行查询时遇到以下错误,查询有什么问题吗?错误究竟意味着什么?有人能指导我为什么以及如何解决它?

代码: -

import elasticsearch
import json
import os
import site
import pprint
import requests
pp = pprint.PrettyPrinter(indent=4)
es = elasticsearch.Elasticsearch(["name.company.com:900"])
CRT_DATA_INDEX = 'crt_data'
CRT_DATA_DOC_TYPE = 'crt_data'

def get_crt_from_es_by_dev_gerrit(dev_gerrit):
    print(dev_gerrit)
    '''
    search_kwargs = {
           "body": {
               "query": {
                   "nested": {
                       "path": "dev_gerrits",
                       "query": {
                          "term": {
                              "number": dev_gerrit
                          }
                       }
                   }
               }
           }
       }
    '''


    search_kwargs = {
        "body": {
            "query": {
                "nested": {
                    "path": "dev_gerrits",
                    "query": {
                        "term": {
                            "number": dev_gerrit
                        }
                    }
                },
                "filtered": {
                    "filter": {
                        "bool": {
                            "must": [
                                {
                                    "term": {
                                        "promotion_status": "MERGED"
                                    }
                                }
                            ]
                        }
                    }
                }
            }
        }
    }


    results = es.search(
          index=CRT_DATA_INDEX,
          doc_type=CRT_DATA_DOC_TYPE,
          size = 1000,
          **search_kwargs)
      # if there is a result, only 1 hit is expected
    pp.pprint(results)

错误: -

Traceback (most recent call last):
  File "dev2rel.py", line 76, in <module>
    output = get_crt_from_es_by_dev_gerrit(1765773)
  File "dev2rel.py", line 65, in get_crt_from_es_by_dev_gerrit
    **search_kwargs)
  File "/usr/local/lib/python2.7/dist-packages/elasticsearch/client/utils.py", line 71, in _wrapped
    return func(*args, params=params, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/elasticsearch/client/__init__.py", line 569, in search
    doc_type, '_search'), params=params, body=body)
  File "/usr/local/lib/python2.7/dist-packages/elasticsearch/transport.py", line 327, in perform_request
    status, headers, data = connection.perform_request(method, url, params, body, ignore=ignore, timeout=timeout)
  File "/usr/local/lib/python2.7/dist-packages/elasticsearch/connection/http_urllib3.py", line 124, in perform_request
    self._raise_error(response.status, raw_data)
  File "/usr/local/lib/python2.7/dist-packages/elasticsearch/connection/base.py", line 122, in _raise_error
    raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info)
elasticsearch.exceptions.RequestError

0 个答案:

没有答案