使用python

时间:2016-04-25 15:01:11

标签: python elasticsearch

所以puamapi / apiobjects_american / 4901对象看起来像这样:

{
"_id": "4701",
"_index": "puamapi",
"_source": {
    "CatRais": null,
    "Classification": "Photographs",
    "Constituents": [],
    "CreditLine": "Gift of H. Kelley Rollings, Class of 1948, and Mrs. Rollings",
    "CuratorApproved": 0,
    "DateBegin": 1921,
    "DateEnd": 1921,
    "Dated": "1921",
    "Department": "Photography",
    "DimensionsLabel": "image: 19.3 x 24.6 cm (7 5/8 x 9 11/16 in.)\r\nsheet: 20.2 x 25.4 cm (7 15/16 x 10 in.)",
    "Edition": null,
    "Medium": "Gelatin silver print",
    "ObjectID": 4701,
    "ObjectNumber": "1995-341",
    "ObjectStatus": "Accessioned Object",
    "Restrictions": "Restricted",
    "SortNumber": "  1995  341",
    "SysTimeStamp": "AAAAAAAAC3k="
},
"_type": "apiobjects_american",
"_version": 4,
"found": true

}

我想对对象进行部分更新,我们在组件数组中添加组件。

记录如下:

{'params': {'item': [{'ConstituentID': 5}]}, 'script': 'if (ctx._source[Constituents] == null) {ctx._source.Constituents = item } else { ctx._source.Constituents+= item }'}

然后我在python中添加了一个弹性搜索实例:

es.update(index="puamapi", doc_type="apiobjects_american", id=4901, body=record)

但是,我收到此错误

Traceback (most recent call last):
  File "json_to_elasticsearch.py", line 138, in <module>
    load_xrefs(api_xrefs)
  File "json_to_elasticsearch.py", line 118, in load_xrefs
    load_xref(table, xref_map[table][0], xref_map[table][1], json.load(file)["RECORDS"])
  File "json_to_elasticsearch.py", line 109, in load_xref
    es.update(index=database, doc_type=table1, id=id1, body=record)
  File "/usr/local/lib/python2.7/dist-packages/elasticsearch/client/utils.py", line 69, in _wrapped
    return func(*args, params=params, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/elasticsearch/client/__init__.py", line 460, in update
    doc_type, id, '_update'), params=params, body=body)
  File "/usr/local/lib/python2.7/dist-packages/elasticsearch/transport.py", line 329, 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 109, in perform_request
    self._raise_error(response.status, raw_data)
  File "/usr/local/lib/python2.7/dist-packages/elasticsearch/connection/base.py", line 108, in _raise_error
    raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info)
elasticsearch.exceptions.RequestError: TransportError(400, u'illegal_argument_exception', u'[Bastion][127.0.0.1:9300][indices:data/write/update[s]]')

任何见解都将不胜感激。谢谢!

0 个答案:

没有答案