作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个Elasticsearch集群,我正在针对多个索引(msearch)运行搜索,该搜索返回一个对象数组(每个要查询的索引一个对象)。这些对象中的每一个在hits对象内部都有一个hits数组。我真的只是在_source对象之后。您将如何获取所有嵌套的“_source”对象的数组?
[
{
"hits": {
"hits": [
{
"_index": "index1",
"_type": "type1",
"_id": "1",
"_score": 12.163426,
"_source": {
"somekey": "some value",
"someotherkey": "another value"
}
}
]
},
},
{
"hits": {
"hits": []
},
},
{
"hits": {
"hits": [
{
"_index": "index2",
"_type": "type2",
"_id": "2",
"_score": 7.0380797,
"_source": {
"somekey": "some value",
"someotherkey": "another value"
}
},
{
"_index": "index2",
"_type": "type2",
"_id": "3",
"_score": 6.07253,
"_source": {
"somekey": "some value 2",
"someotherkey": "another value 2"
}
}
]
},
},
]
最佳答案
您可以使用 Array.prototype.flatMap()
遍历外部数组,并使用 Array.prototype.map()
将hits.hits
转换为_source
属性数组作为项:
const src = [{"hits":{"hits":[{"_index":"index1","_type":"type1","_id":"1","_score":12.163426,"_source":{"somekey":"some value","someotherkey":"another value"}}]},},{"hits":{"hits":[]},},{"hits":{"hits":[{"_index":"index2","_type":"type2","_id":"2","_score":7.0380797,"_source":{"somekey":"some value1","someotherkey":"another value1"}},{"_index":"index2","_type":"type2","_id":"3","_score":6.07253,"_source":{"somekey":"some value 2","someotherkey":"another value 2"}}]},},],
result = src.flatMap(o => o.hits.hits.map(({_source}) => _source))
console.log(result)
.as-console-wrapper{min-height:100%;}
关于javascript - 如何从MSearch返回数组匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63181609/
我的目标是使用multiple search在一个ES请求中发送3个独立的查询 我正在使用NEST客户端使用以下功能将查询发送到Elastic search IElasticClient _elast
我正在尝试运行 a multi search request在 Elasticsearch Python 客户端上。我可以正确运行单一搜索,但无法弄清楚如何格式化 msearch 请求。根据文档,请求
Elasticsearch 版本 - .90.1 以下工作完美。 cat names {"index":"events","type":"news"} {"query":{"term":{"Type"
我是一名优秀的程序员,十分优秀!