gpt4 book ai didi

csv - Elasticsearch 中有什么方法可以在 curl API 中将结果作为 CSV 文件获取?

转载 作者:行者123 更新时间:2023-11-29 02:42:57 29 4
gpt4 key购买 nike

我正在使用 Elasticsearch 。我需要 Elasticsearch 的结果作为 CSV 文件。任何 curl 网址或任何插件来实现这一点?

最佳答案

我已经使用 cURL 和 jq 完成了这项工作(“类似于 sed,但用于 JSON”)。例如,您可以执行以下操作以获取给定方面的前 20 个值的 CSV 输出:

$ curl -X GET 'http://localhost:9200/myindex/item/_search?from=0&size=0' -d '
{"from": 0,
"size": 0,
"facets": {
"sourceResource.subject.name": {
"global": true,
"terms": {
"order": "count",
"size": 20,
"all_terms": true,
"field": "sourceResource.subject.name.not_analyzed"
}
}
},
"sort": [
{
"_score": "desc"
}
],
"query": {
"filtered": {
"query": {
"match_all": {}
}
}
}
}' | jq -r '.facets["subject"].terms[] | [.term, .count] | @csv'

"United States",33755
"Charities--Massachusetts",8304
"Almshouses--Massachusetts--Tewksbury",8304
"Shields",4232
"Coat of arms",4214
"Springfield College",3422
"Men",3136
"Trees",3086
"Session Laws--Massachusetts",2668
"Baseball players",2543
"Animals",2527
"Books",2119
"Women",2004
"Landscape",1940
"Floral",1821
"Architecture, Domestic--Lowell (Mass)--History",1785
"Parks",1745
"Buildings",1730
"Houses",1611
"Snow",1579

关于csv - Elasticsearch 中有什么方法可以在 curl API 中将结果作为 CSV 文件获取?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18892560/

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