Elasticsearch Head插件输出到ES批量导入?

时间:2019-07-17 20:22:00

标签: elasticsearch jq

我通过以下方式使用Elasticsearch Head Chrome插件:

  • 连接到Elasticseach
  • 选择“结构化查询”标签
  • 输入我的搜索条件。
  • 将“输出结果”类型从“表”更改为“ JSON”
  • 点击“搜索”

然后将结果显示在屏幕上。

我想将这个响应和批量加载到另一个Elasticsearch实例中;请注意,当我进行批量插入时,为获取数据而查询的Elasticsearch实例可能不可用,这就是为什么我首先将需要的文件导出到文件的原因。

我正在尝试通过使用jq来实现这一点,如此处所述:Elasticsearch Bulk JSON Data

但是,从Elasticsearch Head插件返回的响应包括其他数据;响应如下所示:

{
    "took": 0,
    "timed_out": false,
    "_shards": {
        "total": 3,
        "successful": 3,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": 2,
        "max_score": 11.975434,
        "hits": [
            {
                "_index": "tommy",
                "_type": "doc",
                "_id": "12345",
                "_score": 11.975434,
                "_source": {
                    "user": {
                        "last_name": "SMITH",
                        "gender_cd": "M",
                        "first_name": "JOHN",
                        "date_of_birth": "1995-02-28T00:00:00",
                        "address": {
                            "state": null,
                            "zip": null,
                            "city": null,
                            "street": null
                        },
                        "race_cd": null
                    },
                    "document_id": "ABC123",
                    "action": "index",
                    "customer_last_name": "SMITH",
                    "customer_first_name": "JOHN",
                    "update_ts": "2019-02-21T14:53:47.000Z"
                }
            },
            {
                "_index": "tommy",
                "_type": "doc",
                "_id": "98765",
                "_score": 11.9225025,
                "_source": {
                    "user": {
                        "last_name": "BOND",
                        "gender_cd": "M",
                        "first_name": "JAMES",
                        "date_of_birth": "1990-02-20T00:00:00",
                        "address": {
                            "state": null,
                            "zip": null,
                            "city": null,
                            "street": null
                        },
                        "race_cd": null
                    },
                    "document_id": "ABC456",
                    "action": "index",
                    "patient_last_name": "BOND",
                    "patient_first_name": "JAMES",
                    "update_ts": "2019-02-21T14:17:27.000Z"
                }
            }
        ]
    }
}

关于如何修改此响应的任何建议,以便我可以使用jq将响应重新格式化为可导入到ES的批量格式?

谢谢。

0 个答案:

没有答案