Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在Elasticsearch查询中从嵌套范围访问父字段?_Javascript_Typescript_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch - Fatal编程技术网 elasticsearch,Javascript,Typescript,elasticsearch" /> elasticsearch,Javascript,Typescript,elasticsearch" />

Javascript 如何在Elasticsearch查询中从嵌套范围访问父字段?

Javascript 如何在Elasticsearch查询中从嵌套范围访问父字段?,javascript,typescript,elasticsearch,Javascript,Typescript,elasticsearch,我有以下对象,其中键是我的组ID,值是每个组的相关代码 Obj: 我将所有键转换为数字数组,并在查询中迭代它们 我想添加一个过滤器,它只接受与我的值相交的代码,但嵌套字段似乎不熟悉我的父迭代组id 这是我的查询->标记了有问题的部分 myFunc(myObj) { groupIds:Array<number> = getAllKeysFromObject(myObj); //GETTING ALL GROUP IDS - will return [1,2] return {

我有以下对象,其中键是我的组ID,值是每个组的相关代码

Obj:

我将所有键转换为数字数组,并在查询中迭代它们

我想添加一个过滤器,它只接受与我的值相交的代码,但嵌套字段似乎不熟悉我的父迭代组id

这是我的查询->标记了有问题的部分

myFunc(myObj) {
groupIds:Array<number> = getAllKeysFromObject(myObj); //GETTING ALL GROUP IDS - will return [1,2]
  return {
        _source: false,
        docvalue_fields: [{
            field: 'group_id',
            format: 'use_field_mapping',
        }],
        query: {
            bool: {
                filter: [{
                    terms: {group_id: groupIds}, //HERE ARE THE GROUP IDS
                }, {
                    nested: {
                        inner_hits: {
                            _source: false,
                            docvalue_fields: [{
                                field: 'products.code',
                                format: 'use_field_mapping',
                            },  
                            ],
                            size: 2,
                            sort: [{[`products.somefield`]: 'desc'}],
                        },
                        path: 'products',
                        query: {
                            bool: {
                              must: [
                                {
                                  terms: {
                                    'products.code': myObj[group_id], //THIS DOES NOT WORK as group_id is not recognised. Would like for group_id=1 to have here [1,2,3] and for next iteration of group_id=2 to get [4,5,6]
                                  },
                                },
                              ],
                            },
                          },
                        },
                      },
                    ],
                  },
                },
        size: 5,
    };
myFunc(myObj){
groupID:Array=getAllKeysFromObject(myObj);//获取所有组ID-将返回[1,2]
返回{
_资料来源:假,
docvalue_字段:[{
字段:“组id”,
格式:“使用_字段_映射”,
}],
查询:{
布尔:{
过滤器:[{
术语:{group_id:groupIds},//以下是组id
}, {
嵌套的:{
内部点击:{
_资料来源:假,
docvalue_字段:[{
字段:“products.code”,
格式:“使用_字段_映射”,
},  
],
尺寸:2,
排序:[{[`products.somefield`]:'desc'}],
},
路径:“产品”,
查询:{
布尔:{
必须:[
{
条款:{
'products.code':myObj[group_id],//这不起作用,因为无法识别group_id。希望group_id=1在这里有[1,2,3],而group_id=2的下一次迭代得到[4,5,6]
},
},
],
},
},
},
},
],
},
},
尺码:5,
};
myFunc(myObj) {
groupIds:Array<number> = getAllKeysFromObject(myObj); //GETTING ALL GROUP IDS - will return [1,2]
  return {
        _source: false,
        docvalue_fields: [{
            field: 'group_id',
            format: 'use_field_mapping',
        }],
        query: {
            bool: {
                filter: [{
                    terms: {group_id: groupIds}, //HERE ARE THE GROUP IDS
                }, {
                    nested: {
                        inner_hits: {
                            _source: false,
                            docvalue_fields: [{
                                field: 'products.code',
                                format: 'use_field_mapping',
                            },  
                            ],
                            size: 2,
                            sort: [{[`products.somefield`]: 'desc'}],
                        },
                        path: 'products',
                        query: {
                            bool: {
                              must: [
                                {
                                  terms: {
                                    'products.code': myObj[group_id], //THIS DOES NOT WORK as group_id is not recognised. Would like for group_id=1 to have here [1,2,3] and for next iteration of group_id=2 to get [4,5,6]
                                  },
                                },
                              ],
                            },
                          },
                        },
                      },
                    ],
                  },
                },
        size: 5,
    };