简体   繁体   English

如何使用pyes将普通查询发送到elasticsearch

[英]how to send a plain query to elasticsearch with pyes

I have a plain query that I would like to send to Elasticsearch through pyes without using pyes's builtin methods. 我有一个简单的查询,我想通过pyes发送给Elasticsearch,而不使用pyes的内置方法。 The query works when it's CURLed. 当查询被卷曲时,该查询起作用。

further below is my code, but I can't make it work. 下面是我的代码,但无法正常工作。 It returns this error when I iterate over the result object 当我遍历结果对象时,它将返回此错误

Traceback (most recent call last):
  File "testQualifier.py", line 9, in <module>
    for r in results:
  File "/usr/local/lib/python2.7/dist-packages/pyes/es.py", line 1384, in __next__
    self._do_search()
  File "/usr/local/lib/python2.7/dist-packages/pyes/es.py", line 1212, in _do_search
    self._results = self._search_raw(self.start, self.chuck_size)
  File "/usr/local/lib/python2.7/dist-packages/pyes/es.py", line 1428, in _search_raw
    doc_types=self.doc_types, headers=self.headers, **query_params)
  File "/usr/local/lib/python2.7/dist-packages/pyes/es.py", line 931, in search_raw
    return self._send_request('GET', path, body, params=query_params, headers=headers)
  File "/usr/local/lib/python2.7/dist-packages/pyes/es.py", line 419, in _send_request
    raise_if_error(response.status, decoded)
  File "/usr/local/lib/python2.7/dist-packages/pyes/convert_errors.py", line 94, in raise_if_error
    raise exceptions.ElasticSearchException(error, status, result, request)
pyes.exceptions.ElasticSearchException: QueryParsingException[[test] No query registered for [facets]]; }]

Can anyone point me into the right direction? 谁能指出我正确的方向?

#!/usr/bin/env python
#-*- coding: utf-8 -*-

from pyes import *
import json
conn = ES('127.0.0.1:9200') # Use HTTP
q = {
  "facets": {
    "terms": {
      "terms": {
        "field": "Breadcrumb",
        "size": 2,
        "order": "count",
        "exclude": []
      },
      "facet_filter": {
        "fquery": {
          "query": {
            "filtered": {
              "query": {
                "bool": {
                  "should": [
                    {
                      "query_string": {
                        "fields": [
                          "Title"
                        ],
                        "query": "solar panel"
                      }
                    }
                  ]
                }
              },
              "filter": {
                "bool": {
                  "must": [
                    {
                      "fquery": {
                        "query": {
                          "query_string": {
                            "query": "VendorName:(\"abcdedf\")"
                          }
                        },
                        "_cache": true
                      }
                    }
                  ]
                }
              }
            }
          }
        }
      }
    }
  },
  "size": 0
}
results = conn.search(query = q)
for r in results:
    print r

found it out. 发现了。 this works... 这可行...

#!/usr/bin/env python
#-*- coding: utf-8 -*-

from pyes import *


conn = ES('127.0.0.1:9200') # Use HTTP

q = {
  "facets": {
    "terms": {
      "terms": {
        "field": "Breadcrumb",
        "size": 2,
        "order": "count",
        "exclude": []
      },
      "facet_filter": {
        "fquery": {
          "query": {
            "filtered": {
              "query": {
                "bool": {
                  "should": [
                    {
                      "query_string": {
                        "fields": [
                          "Title"
                        ],
                        "query": "solar panel"
                      }
                    }
                  ]
                }
              },
              "filter": {
                "bool": {
                  "must": [
                    {
                      "fquery": {
                        "query": {
                          "query_string": {
                            "query": "VendorName:(\"abcdef\")"
                          }
                        },
                        "_cache": true
                      }
                    }
                  ]
                }
              }
            }
          }
        }
      }
    }
  },
  "size": 0
}

results = conn._send_request('GET', 'vendor/_search', q)
for r in results:
    print r

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM