本文介绍了有什么方法在Elasticsearch中获取结果作为CSV文件在curl api?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用弹性搜索。
我需要弹性搜索的结果作为csv文件。
任何curl url或任何插件来实现这一点?
提前感谢。
I am using elastic search. I need results from elastic search as a csv file. Any curl url or any plugins to achieve this?Thanks in advance.
推荐答案
我使用cURL和(like sed
,but for JSON)。例如,您可以执行以下操作以获取给定构面的前20个值的CSV输出:
I've done just this using cURL and jq ("like sed
, but for JSON"). For example, you can do the following to get CSV output for the top 20 values of a given facet:
$ 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
这篇关于有什么方法在Elasticsearch中获取结果作为CSV文件在curl api?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!