apoc.es.put

过程 Apoc 扩展

apoc.es.put(host-or-key,index-or-null,type-or-null,id-or-null,query-or-null,payload-or-null,$config) yield value - 在 elastic search 上执行 PUT 操作

签名

apoc.es.put(host :: STRING?, index :: STRING?, type :: STRING?, id :: STRING?, query :: ANY?, config = {} :: MAP?) :: (value :: MAP?)

输入参数

名称 类型 默认

host

STRING?

null

index

STRING?

null

type

STRING?

null

id

STRING?

null

query

ANY?

null

payload

MAP?

{}

config

MAP?

{}

输出参数

名称 类型

MAP?

使用示例

本节中的示例基于以下 Elastic 实例

version: '3.5'
services:
  elastic:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.10.0
    ports:
      - 9200:9200
      - 9300:9300
    environment:
      - discovery.type=single-node

该实例的数据集通过下载 此文件 并执行命令创建

curl -H 'Content-Type: application/json' -XPOST 'localhost:9200/bank/_bulk?pretty&refresh' --data-binary '@accounts.json'

我们可以通过运行以下查询,在 customers 索引中创建一个 name 属性为 John Doe 且文档 ID 为 2 的文档:

CALL apoc.es.put("localhost","customers","_doc", "2", null, {
  name: "John Doe"
});
表 1. 结果

{result: "created", _shards: {total: 2, failed: 0, successful: 1}, _seq_no: 2, _index: "customers", _type: "_doc", _id: "2", _version: 1, _primary_term: 1}

我们可以通过运行以下查询来更新此文档以添加地址:

CALL apoc.es.put("localhost","customers","_doc", "2", null, {
  name: "John Doe",
  address: "Buckingham Palace"
});
表 2. 结果

{result: "updated", _shards: {total: 2, failed: 0, successful: 1}, _seq_no: 5, _index: "customers", _type: "_doc", _id: "2", _version: 2, _primary_term: 1}

© . This site is unofficial and not affiliated with Neo4j, Inc.