gpt4 book ai didi

json - 如何批量更改Elastic Search的JSON格式

转载 作者:行者123 更新时间:2023-12-02 23:22:57 26 4
gpt4 key购买 nike

我采用以下格式,并希望使用elasticsearch进行批量处理。

{"title":"April","url":"https://simple.wikipedia.org/wiki/April", "abstract":"April is the 4th month of the year, and comes between March and May. It is one of four months to have 30 days.","sections":["The Month","April in poetry","Events in April","Fixed Events","Moveable Events","Selection of Historical Events","Trivia","References"]}
{"title":"August","url":"https://simple.wikipedia.org/wiki/August", "abstract":"August (Aug.) is the 8th month of the year in the Gregorian calendar, coming between July and September.","sections":["The Month","August observances","Fixed observances and events","Moveable and Monthlong events","Selection of Historical Events","Trivia","References"]}

我试图在每行之前添加index,type行。
{"index":{"_index":"myindex","_type":"wiki","_id":"1"}}

阅读以前的帖子时,我使用 Kevin Marsh's post如下所示:
cat file.json jq -c '.[] | {"index": {"_index": "myindex", "_type": "wiki", "_id": .id}}, .' 

我没有使用管道,因为我试图找出之前的错误。我收到错误jq:没有这样的文件或目录。然后,我使用了 jq --version and get jq-1.5-1-a5b5cbe

任何帮助深表感谢。

最佳答案

干得好。这对我有用。让我知道是否有帮助。

cat data.json | jq -c '. | {"index": {"_index": "json", "_type": "json"}}, .'  | curl -XPOST localhost:9200/_bulk --data-binary @-

了解有关 jq : a lightweight and flexible command-line JSON processor的更多信息。

关于json - 如何批量更改Elastic Search的JSON格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46794935/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com