简体   繁体   English

使用带有Elasticsearch的DSL查询嵌套字段

[英]Query nested fields using DSL with elasticsearch

When I try to query a nested field that exists, I didn't get any result (it isn't return any error): 当我尝试查询存在的嵌套字段时,没有得到任何结果(它没有返回任何错误):

                result = es.search(
                          index="mydb", 
                          doc_type="collection", 
                          body={"query": 
                            { 
                                  "term" : {
                                      "foo.bar.field" : value
                                  }
                            }
                          }
                        )

NOTE: field is inside bar and bar is inside foo: 注意:字段在bar内部,而bar在foo内部:

{ 'topfield' : 23, 'foo' : { 'bar' : { 'field' : 69 }, 'otherfield' : 1}}

If I try the same with a field in the top, it works properly: 如果我尝试使用顶部的字段进行相同操作,则可以正常工作:

                result = es.search(
                          index="mydb", 
                          doc_type="collection", 
                          body={"query": 
                            { 
                                  "term" : {
                                      "topfield" : value
                                  }
                            }
                          }
                        )

I suppose the query should be as below. 我想查询应该如下。 i think there is a mismatch in the field bar=>var as seen from the below document. 我认为从下面的文档中可以看出,栏bar => var中存在不匹配。

{ 'topfield' : 23, 'foo' : { 'var' : { 'field' : 69 }, 'otherfield' : 1}}

Please try the code below 请尝试下面的代码

            result = es.search(
                      index="mydb", 
                      doc_type="collection", 
                      body={"query": 
                        { 
                              "term" : {
                                  "foo.var.field" : value
                              }
                        }
                      }
                    )

could you please confirm on this. 能请你确认一下。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM