当python包与文档不匹配时,如何在elasticsearch中放置enrich策略

pftdvrlh  于 7个月前  发布在  ElasticSearch
关注(0)|答案(1)|浏览(94)

我尝试在elasticsearch对应的摄取管道之前将一个简单的enrich策略放置到elasticsearch上。我遇到的问题是当我执行时:

if enrich_policies:
        for i, (name, body) in enumerate(enrich_policies.items()):
            result = es.enrich.get_policy(name=name)
            
            if "config" in body:
                body = body["config"]
        
            # cannot pass in "body", but the individual params 
            # https://www.elastic.co/guide/en/elasticsearch/reference/current/put-enrich-policy-api.html#put-enrich-policy-api-request-body
            body_match = body.get("match")
            body_range = body.get("range")
            body_geo_match = body.get("geo_match")
            
            log_print(f"Putting policy {name} with match: {body_match}, range: {body_range}, geo_match: {body_geo_match}", "DEBUG")
        
            # upload enrich policy
            result = es.enrich.put_policy(name=name, match=body_match, range=body_range, geo_match=body_geo_match)
            
            # execute enrich policy
            result = es.enrich.execute_policy(name=name)

字符串
我得到这个错误:

File "C:\Users\xxx\source\xxx\configure_kibana_objects.py", line 152, in <module>
    main()
  File "C:\Users\xxx\source\xxx\configure_kibana_objects.py", line 116, in main
    result = es.enrich.put_policy(name=name, match=body_match, range=body_range, geo_match=body_geo_match)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\elasticsearch\_sync\client\utils.py", line 414, in wrapped
    return api(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\elasticsearch\_sync\client\enrich.py", line 188, in put_policy
    return self.perform_request(  # type: ignore[return-value]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\elasticsearch\_sync\client\_base.py", line 389, in perform_request
    return self._client.perform_request(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\elasticsearch\_sync\client\_base.py", line 320, in perform_request
    raise HTTP_EXCEPTIONS.get(meta.status, ApiError)(
elasticsearch.BadRequestError: BadRequestError(400, 'x_content_parse_exception', '[1:11] [policy] unknown field [name]')


Elasticsearch版本8.7.0

python -m pip show elasticsearch
Version: 8.7.0
Summary: Python client for Elasticsearch
Home-page: https://github.com/elastic/elasticsearch-py
Author: Honza Král, Nick Lang
Author-email: honz[email protected], [email protected]
License: Apache-2.0
Location: C:\Python311\Lib\site-packages
Requires: elastic-transport
Required-by:


下面是该包的文档链接,其中包括第一个参数:name
那么,为什么软件包一直对我大喊大叫,说没有参数name

gwbalxhn

gwbalxhn1#

有三种不同类型的丰富策略可用范围,match或geo_match。您需要创建一种类型的策略,然后调用execute policy来创建该丰富索引。

body={
  "match": {
    "indices": "student_data_index",
    "match_field": "registration_id",
    "enrich_fields": [ 
            "first_name",
            "last_name",
            "date_of_birth",
            "father_name"
      ]
  }
}
client.enrich.put_policy(name="student_enrich_policy",body =body)

字符串
执行丰富索引

client.enrich.execute_policy(name="student_enrich_policy", wait_for_completion=True)

相关问题