Elasticsearch Reindex API不工作

Elasticsearch Reindex API不工作,
Warning: implode(): Invalid arguments passed in /data/phpspider/zhask/webroot/tpl/detail.html on line 45
,,我正在尝试将reindex api用于elasticsearch 这是我的源代码索引 "testtype": { "_all": { "enabled": false }, "dynamic_templates": [ { "message_field": { "mapping": { "fielddata": {

我正在尝试将reindex api用于elasticsearch

这是我的源代码索引

"testtype": {
        "_all": {
          "enabled": false
        },
        "dynamic_templates": [
          {
            "message_field": {
              "mapping": {
                "fielddata": {
                  "format": "disabled"
                },
                "index": "analyzed",
                "omit_norms": true,
                "type": "string"
              },
              "match": "message",
              "match_mapping_type": "string"
            }
          },
          {
            "string_fields": {
              "mapping": {
                "fielddata": {
                  "format": "disabled"
                },
                "index": "analyzed",
                "omit_norms": true,
                "type": "string",
                "fields": {
                  "raw": {
                    "ignore_above": 256,
                    "index": "not_analyzed",
                    "type": "string"
                  }
                }
              },
              "match": "*",
              "match_mapping_type": "string"
            }
          }
        ],
        "properties": {
          "@timestamp": {
            "type": "date",
            "format": "strict_date_optional_time||epoch_millis"
          },
          "@version": {
            "type": "string",
            "index": "not_analyzed"
          },
          "app_code": {
            "type": "string"
          },
          "data": {
            "properties": {
              "action": {
                "type": "string",
                "norms": {
                  "enabled": false
                },
                "fielddata": {
                  "format": "disabled"
                },
                "fields": {
                  "raw": {
                    "type": "string",
                    "index": "not_analyzed",
                    "ignore_above": 256
                  }
                }
              },
              "level": {
                "type": "string",
                "norms": {
                  "enabled": false
                },
                "fielddata": {
                  "format": "disabled"
                },
                "fields": {
                  "raw": {
                    "type": "string",
                    "index": "not_analyzed",
                    "ignore_above": 256
                  }
                }
              },
              "message": {
                "type": "string",
                "norms": {
                  "enabled": false
                },
                "fielddata": {
                  "format": "disabled"
                }
              },
              "timestamp": {
                "type": "date",
                "format": "strict_date_optional_time||epoch_millis"
              }
            }
          },
          "header": {
            "properties": {
              "@timestamp": {
                "type": "date",
                "format": "strict_date_optional_time||epoch_millis"
              },
              "_id": {
                "type": "long"
              },
              "app_code": {
                "type": "string",
                "norms": {
                  "enabled": false
                },
                "fielddata": {
                  "format": "disabled"
                },
                "fields": {
                  "raw": {
                    "type": "string",
                    "index": "not_analyzed",
                    "ignore_above": 256
                  }
                }
              },
              "host": {
                "type": "string",
                "norms": {
                  "enabled": false
                },
                "fielddata": {
                  "format": "disabled"
                },
                "fields": {
                  "raw": {
                    "type": "string",
                    "index": "not_analyzed",
                    "ignore_above": 256
                  }
                }
              },
              "meta_host": {
                "type": "string",
                "norms": {
                  "enabled": false
                },
                "fielddata": {
                  "format": "disabled"
                },
                "fields": {
                  "raw": {
                    "type": "string",
                    "index": "not_analyzed",
                    "ignore_above": 256
                  }
                }
              },
              "name": {
                "type": "string",
                "norms": {
                  "enabled": false
                },
                "fielddata": {
                  "format": "disabled"
                },
                "fields": {
                  "raw": {
                    "type": "string",
                    "index": "not_analyzed",
                    "ignore_above": 256
                  }
                }
              },
              "pid": {
                "type": "long"
              },
              "source_id": {
                "type": "string",
                "norms": {
                  "enabled": false
                },
                "fielddata": {
                  "format": "disabled"
                },
                "fields": {
                  "raw": {
                    "type": "string",
                    "index": "not_analyzed",
                    "ignore_above": 256
                  }
                }
              },
              "source_name": {
                "type": "string",
                "norms": {
                  "enabled": false
                },
                "fielddata": {
                  "format": "disabled"
                },
                "fields": {
                  "raw": {
                    "type": "string",
                    "index": "not_analyzed",
                    "ignore_above": 256
                  }
                }
              },
              "timestamp": {
                "type": "date",
                "format": "strict_date_optional_time||epoch_millis"
              },
              "user": {
                "type": "string",
                "norms": {
                  "enabled": false
                },
                "fielddata": {
                  "format": "disabled"
                },
                "fields": {
                  "raw": {
                    "type": "string",
                    "index": "not_analyzed",
                    "ignore_above": 256
                  }
                }
              }
            }
          },
          "source_id": {
            "type": "string"
          },
          "timestamp": {
            "type": "date",
            "format": "strict_date_optional_time||epoch_millis"
          }
        }
      }
因此它有一些
string
字段,这些字段也有相应的原始字段。问题是默认字段是经过分析的
。所以我希望新的索引是

{
  "mappings": {
    "test": {
        "dynamic_templates": [
            { "notanalyzed": {
                  "match": "*",
                  "path_unmatch":"data.message",
                  "match_mapping_type": "string",
                  "mapping": {
                      "type":        "string",
                      "index":       "not_analyzed",
                      "fielddata": {
                      "format": "disabled"
                    },
                    "fields": {
                      "raw": {
                        "ignore_above": 256,
                        "index": "not_analyzed",
                        "type": "string"
                      }
                    }
                  }
               }
            }
          ]
       }
   }
}
旧索引有一些数据。所以我试着把它重新定义为

POST /_reindex
{
  "source": {
    "index": "oldindex",
    "type": ["testtype"]
  },
  "dest": {
    "index": "newindex"
  }
}
完成此操作后,我看到新索引已转换为

{
  "newindex": {
    "aliases": {},
    "mappings": {
      "testtype": {
        "properties": {
          "data": {
            "properties": {
              "action": {
                "type": "string"
              },
              "level": {
                "type": "string"
              },
              "message": {
                "type": "string"
              },
              "timestamp": {
                "type": "date",
                "format": "strict_date_optional_time||epoch_millis"
              }
            }
          },
          "header": {
            "properties": {
              "@timestamp": {
                "type": "date",
                "format": "strict_date_optional_time||epoch_millis"
              },
              "_id": {
                "type": "long"
              },
              "app_code": {
                "type": "string"
              },
              "host": {
                "type": "string"
              },
              "meta_host": {
                "type": "string"
              },
              "name": {
                "type": "string"
              },
              "pid": {
                "type": "long"
              },
              "source_id": {
                "type": "string"
              },
              "source_name": {
                "type": "string"
              },
              "timestamp": {
                "type": "date",
                "format": "strict_date_optional_time||epoch_millis"
              },
              "user": {
                "type": "string"
              }
            }
          }
        }
      },
      "test": {
        "dynamic_templates": [
          {
            "notanalyzed": {
              "mapping": {
                "fielddata": {
                  "format": "disabled"
                },
                "index": "not_analyzed",
                "type": "string",
                "fields": {
                  "raw": {
                    "ignore_above": 256,
                    "index": "not_analyzed",
                    "type": "string"
                  }
                }
              },
              "match": "*",
              "match_mapping_type": "string",
              "path_unmatch": "data.message"
            }
          }
        ]
      }
    },
    "settings": {
      "index": {
        "creation_date": "1461792130202",
        "number_of_shards": "5",
        "number_of_replicas": "1",
        "uuid": "nho7V2PpTbqzfsUVWVdLkA",
        "version": {
          "created": "2030099"
        }
      }
    },
    "warmers": {}
  }
}
我不明白这里发生了什么事!看起来新数据只是自动索引的!这根本不是我想要的

我甚至试过

POST /_reindex
{
  "source": {
    "index": "oldindex",
    "type": ["testtype"]
  },
  "dest": {
    "index": "newindex",
    "type": ["test"]
  }
}
但现在我明白了

{
   "error": "org.elasticsearch.ElasticsearchParseException: Unknown array field [type]"
}
我做错了什么?我不能使用elasticdump或背包,因为它们是第三方插件。

你就快到了

  • 删除错误创建的索引:
    删除新索引
  • 创建
    newindex
    索引:
  • 并使用此稍加修改的
    \u reindex
    命令:

重要的一点是
脚本
,您在脚本中告诉
\u reindex
API更改
\u newindex

中文档的
\u类型
,谢谢,这更有意义。但是,现在我得到了“type”:“script\u exception”,“reason”:“类型[inline]、操作[update]和lang[groovy]的脚本被禁用”`这是什么意思?忘了这一点。您需要在
elasticsearch.yml
script.engine.groovy.inline.update:true
中启用脚本并重新启动。如果我指定
“dest”:{“index”:“abtclm2”,“type”:“test”}
dest中的类型与源代码中的类型不同,它是数组。现在,我看到所有的文件都没有转移。过了一会儿,post/_重新索引被终止,我看到
502坏网关:注册的端点无法处理请求。
这意味着什么?如果我试图在完成之前获取统计数据,重新索引操作会受到干扰吗?老实说,我不确定。我不认为统计数据会干扰重新索引操作。。。
PUT /newindex
{
  "mappings": {
    "test": {
      "dynamic_templates": [
        {
          "notanalyzed": {
            "match": "*",
            "path_unmatch": "data.message",
            "match_mapping_type": "string",
            "mapping": {
              "type": "string",
              "index": "not_analyzed",
              "fielddata": {
                "format": "disabled"
              },
              "fields": {
                "raw": {
                  "ignore_above": 256,
                  "index": "not_analyzed",
                  "type": "string"
                }
              }
            }
          }
        }
      ]
    }
  }
}
POST /_reindex
{
  "source": {
    "index": "oldindex",
    "type": [
      "testtype"
    ]
  },
  "dest": {
    "index": "newindex"
  },
  "script": {
    "inline": "ctx._type='test'"
  }
}