painlessで以下のようなデータを扱っています。
{
"_shards": {
"total": 6,
"failed": 0,
"successful": 6,
"skipped": 0
},
"hits": {
"hits": [
{
"_index": "test-2021.07.20",
"_type": "_doc",
"_source": {
"response_status": "403",
"time_cw": "1623984183618",
"src_ip": "10.111.16.62",
"port": "443",
},
"_id": "H_XawnoBjxCrCBvt7vpr",
"_score": 1
},
{
"_index": "test-2021.07.20",
"_type": "_doc",
"_source": {
"response_status": "200",
"time_cw": "1623984201618",
"src_ip": "10.111.68.10",
"port": "443",
},
"_id": "IPXawnoBjxCrCBvt7vpr",
"_score": 1
},
{
"_index": "test-2021.07.20",
"_type": "_doc",
"_source": {
"response_status": "403",
"time_cw": "1623984183618",
"src_ip": "10.111.16.62",
"port": "443",
},
"_id": "JfXcwnoBjxCrCBvtX_p_",
"_score": 1
}
],
"total": {
"value": 3,
"relation": "eq"
},
"max_score": 1
},
"took": 1,
"timed_out": false
}
ドキュメント数分ループさせ、条件に一致するドキュメントのみ別の配列に入れたいです。
■実現したいこと
(script例) response_statusが403のドキュメントのみ、別の配列に入れる
int score = 0;
for (int i = 0; i < ctx.results[0].hits.hits.length; i++) {
if (ctx.results[0].hits.hits[i]._source.response_status == "403") {
★ここで「ctx.results[0].hits.hits[i]」以下を別配列に入れたい
}
}
結果、以下のみを別配列に格納し、以降の処理で使用したいです。
{
"hits": {
"hits": [
{
"_index": "test-2021.07.20",
"_type": "_doc",
"_source": {
"response_status": "403",
"time_cw": "1623984183618",
"src_ip": "10.111.16.62",
"port": "443",
},
"_id": "H_XawnoBjxCrCBvt7vpr",
"_score": 1
},
{
"_index": "test-2021.07.20",
"_type": "_doc",
"_source": {
"response_status": "403",
"time_cw": "1623984183618",
"src_ip": "10.111.16.62",
"port": "443",
},
"_id": "JfXcwnoBjxCrCBvtX_p_",
"_score": 1
}
]
}
painlessでこのような実装は可能でしょうか