gpt4 book ai didi

elasticsearch - 如何在查询中同时返回嵌套字段和非嵌套字段?

转载 作者:行者123 更新时间:2023-12-03 00:15:45 27 4
gpt4 key购买 nike

我有一个具有以下映射的索引:

{
"build": {
"properties": {
"info": {
"properties": {
"ci": {
"properties": {
"generic": {
"properties": {
"job": { ... }
}
}
}
}
}
},
"tests": {
"type": "nested",
"properties": {
"className": { ... }
"result": {
"properties": {
"status": { ... }
}
}
}
}
}
}
}

看起来像什么查询将返回共同关联的 info.ci.generic.job和仅与 tests和嵌套查询 info.ci.generic.job都匹配的 tests.result.status

最佳答案

_sourceinner_hits的组合将满足您的要求:

{
"_source": "info.ci.generic",
"query": {
"filtered": {
"filter": {
"and": [
{
"term": {
"info.ci.generic.job.raw": "my-job-name"
}
},
{
"nested": {
"path": "tests",
"query": {
"term": {
"tests.result.status": "failure"
}
},
"inner_hits": {
"size": 16777216
}
}
}
]
}
}
}
}

结果:
{
"hits": {
"hits": [
{
"inner_hits": {
"tests": {
"hits": {
"hits": [
{
"_source": {
"status": "failure"
}
}
]
}
}
},
"_source": {
"info": {
"ci": {
"generic": {
"user": "builds",
"build": "18471",
"job": "CPIE-family-all-test",
"host": "http://platform.builds.test.netflix.net/"
}
}
}
}
}
]
}
}

关于elasticsearch - 如何在查询中同时返回嵌套字段和非嵌套字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36071949/

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