gpt4 book ai didi

python - 检索没有 _source 字段的数据 :

转载 作者:太空宇宙 更新时间:2023-11-03 15:43:35 24 4
gpt4 key购买 nike

我是elasticsearch的新手,我正在做一个匹配所有查询,它以这种方式检索数据,但只有我想要在_source中检索数据,我该怎么做?有什么想法吗?

    {
"took": 4,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 107271,
"max_score": 1,
"hits": [
{
"_index": "sku_index",
"_type": "po",
"_id": "0",
"_score": 1,
"_source": {
"loc": "ZZZ",
"part": "PPP",
"order_qty": "16",
}
},
{
"_index": "sku_index",
"_type": "po",
"_id": "14",
"_score": 1,
"_source": {
"loc": "ZZZ",
"part": "XXX",
"order_qty": "7",
},
{
"_index": "sku_index",
"_type": "po",
"_id": "14",
"_score": 1,
"_source": {
"loc": "ZZZ",
"part": "ZZZ",
"order_qty": "7",
}
}
.......

我想要这样的东西:

      [{
"loc": "ZZZ",
"part": "PPP",
"order_qty": "16",
},
{
"loc": "ZZZ",
"part": "XXX",
"order_qty": "16",
},
{
"loc": "ZZZ",
"part": "ZZZ",
"order_qty": "7",
}
]

最佳答案

一种可能的方法是 source filtering ,通过添加到您的查询

"_source": {
"includes": [ "loc", "part", "order_qty" ],
"excludes": [ "not_needed_field" ]
},

另一种方式,如果您的字段是 stored (由于需要额外的空间,情况并非总是如此,并且通常不推荐。

By default, field values are indexed to make them searchable, but they are not stored. This means that the field can be queried, but the original field value cannot be retrieved.

因此您需要添加到查询中:

"stored_fields" : ["loc", "part", "order_qty"]

关于python - 检索没有 _source 字段的数据 :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41957002/

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