elasticsearch - 当 _id 等于特定字段时尝试使用 Elasticsearch Bulk API
问题描述
我正在尝试将文档批量插入索引。我需要让 _id 等于我要插入的特定字段。我正在使用 ES v6.6
POST productv9/_bulk
{ "index" : { "_index" : "productv9", "_id": "in_stock"}}
{ "description" : "test", "in_stock" : "2001"}
GET productv9/_search
{
"query": {
"match": {
"_id": "2001"
}
}
}
当我运行批量语句时,它运行时没有任何错误。但是,当我运行搜索语句时,它没有得到任何点击。此外,我还有许多其他文档,我想以相同的方式插入。
解决方案
我建议做的是创建一个摄取管道,它将根据字段_id
的值设置您的文档。in_stock
首先创建管道:
PUT _ingest/pipeline/set_id
{
"description" : "Sets the id of the document based on a field value",
"processors" : [
{
"set" : {
"field": "_id",
"value": "{{in_stock}}"
}
}
]
}
然后您可以在批量调用中引用管道:
POST productv9/doc/_bulk?pipeline=set_id
{ "index" : {}}
{ "description" : "test", "in_stock" : "2001"}
通过打电话GET productv9/_doc/2001
,你会得到你的文件。
推荐阅读
- sql-server - 导出 SSMS 查询结果时,将遇到的每个空格字符替换为逗号?
- c# - 从 C# 插入 QODBC
- google-apps-script - 如何修复 Google 表格 RTL?
- php - 在 MySQL 中将 unix 时间戳转换为以毫秒为单位的日期时间
- c# - Crystal Reports 无法在 IIS 10 和 Windows Server 2019 上运行
- r - 使用 AnomalyDetectionTs 包在 R 中进行时间序列异常检测
- authentication - IBM IAM IamAuthenticator getToken 不是函数
- macos - 如何在启动时删除终端中的“空白空间”?
- mongodb-stitch - Owner_id 字段未通过验证错误。我的架构有什么问题?
- oracle - 语句级触发器或行级触发器