zoukankan      html  css  js  c++  java
  • elasticsearch bulk操作

    Elasticsearch Bulk Index JSON Data
    
    
    我想尝试 buld index 一个json文件到一个新的Elasticsearch index 但是不能这么做,我有下面的json数据
    
    
    [{"Amount": "480", "Quantity": "2", "Id": "975463711", "Client_Store_sk": "1109"},
    {"Amount": "2105", "Quantity": "2", "Id": "975463943", "Client_Store_sk": "1109"},
    {"Amount": "2107", "Quantity": "3", "Id": "974920111", "Client_Store_sk": "1109"},
    {"Amount": "2115", "Quantity": "2", "Id": "975463798", "Client_Store_sk": "1109"},
    {"Amount": "2116", "Quantity": "1", "Id": "975463827", "Client_Store_sk": "1109"},
    {"Amount": "648", "Quantity": "3", "Id": "975464139", "Client_Store_sk": "1109"},
    {"Amount": "2126", "Quantity": "2", "Id": "975464805", "Client_Store_sk": "1109"},
    {"Amount": "2133", "Quantity": "1", "Id": "975464061", "Client_Store_sk": "1109"},
    {"Amount": "1339", "Quantity": "4", "Id": "974919458", "Client_Store_sk": "1109"},
    {"Amount": "1196", "Quantity": "5", "Id": "974920538", "Client_Store_sk": "1109"},
    {"Amount": "1198", "Quantity": "4", "Id": "975463638", "Client_Store_sk": "1109"},
    {"Amount": "1345", "Quantity": "4", "Id": "974919522", "Client_Store_sk": "1109"},
    {"Amount": "1347", "Quantity": "2", "Id": "974919563", "Client_Store_sk": "1109"},
    {"Amount": "673", "Quantity": "2", "Id": "975464359", "Client_Store_sk": "1109"},
    {"Amount": "2153", "Quantity": "1", "Id": "975464511", "Client_Store_sk": "1109"},
    {"Amount": "3896", "Quantity": "4", "Id": "977289342", "Client_Store_sk": "1109"},
    {"Amount": "3897", "Quantity": "4", "Id": "974920602", "Client_Store_sk": "1109"}]
    
    
    
    当我尝试使用标准的buld index api 从elasticseach 我得到了这个错误
    
    {"message":"ActionRequestValidationException[Validation Failed: 1: no requests added;]"}
    
    
    你需要做的是读取那个JSON文件,创建一个bulk 请求格式的
    
    
    即一行用于命令和一行用于文档,用换行符隔开,重复每个文档
    
    curl -XPOST localhost:9200/your_index/_bulk -d '
    {"index": {"_index": "your_index", "_type": "your_type", "_id": "975463711"}}
    {"Amount": "480", "Quantity": "2", "Id": "975463711", "Client_Store_sk": "1109"}
    {"index": {"_index": "your_index", "_type": "your_type", "_id": "975463943"}}
    {"Amount": "2105", "Quantity": "2", "Id": "975463943", "Client_Store_sk": "1109"}
    ... etc for all your documents
    '
    
    
    curl -X POST $elasticsearchwebaddress/_bulk -d '
    { "delete": { "_index": "website", "_type": "blog", "_id": "123" }} 
    { "create": { "_index": "website", "_type": "blog", "_id": "123" }}
    { "title":    "My first blog post" }
    { "index":  { "_index": "website", "_type": "blog" }}
    { "title":    "My second blog post" }
    { "update": { "_index": "website", "_type": "blog", "_id": "123", "_retry_on_conflict" : 3} }
    { "doc" : {"title" : "My updated blog post"} }
    '
    
    
    一行用于命令行,一行用于文档,用换行分开
    
    
    
    
    
    
    

  • 相关阅读:
    vSan中见证组件witness详解
    zabbix监控企业esxi虚拟机
    新特性之MAPI over HTTP 配置 MAPI over HTTP
    Exchange Server 产品路线图 及 补丁下载
    人生的第一桶金
    这不是我想要的生活,努力才是王道!
    孤独的灵魂该去何处安家
    如何查看myeclipse是否激活
    Visual Studio 2013如何破解(密钥激活)
    unity破解步骤
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349895.html
Copyright © 2011-2022 走看看