# Query problem with nested fields using DSL with elasticsearch

**URL:** <https://discuss.elastic.co/t/query-problem-with-nested-fields-using-dsl-with-elasticsearch/20262>\
**Category:** Elasticsearch\
**Created:** [October 15, 2014, 8:38am UTC](https://discuss.elastic.co/t/query-problem-with-nested-fields-using-dsl-with-elasticsearch/20262 "2014-10-15T08:38:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jose\_Ramon\_Palanco](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jose_ramon_palanco/32/1204_2.png) [@Jose\_Ramon\_Palanco](https://discuss.elastic.co/u/Jose_Ramon_Palanco)\
**Post date:** [October 15, 2014, 8:38am UTC](https://discuss.elastic.co/t/query-problem-with-nested-fields-using-dsl-with-elasticsearch/20262/1 "2014-10-15T08:38:24Z")

</div>

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:

{ '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
                              }
                        }
                      }
                    )

```

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/93d419b4-f409-4c57-a2e0-fe528efd3569%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/93d419b4-f409-4c57-a2e0-fe528efd3569%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Ramy](https://avatars.discourse-cdn.com/v4/letter/r/8491ac/32.png) [@Ramy](https://discuss.elastic.co/u/Ramy)\
**Post date:** [October 15, 2014, 8:44am UTC](https://discuss.elastic.co/t/query-problem-with-nested-fields-using-dsl-with-elasticsearch/20262/2 "2014-10-15T08:44:34Z")

</div>

You should use path for your nested fields!!!  
please read this article:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

Am Mittwoch, 15. Oktober 2014 10:38:24 UTC+2 schrieb José Ramón Palanco:

> 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:
> 
> { '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
> }
> }
> }
> )
> 
> ```

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/6e045b5f-b709-49a1-9422-5c5bb8ffb8ef%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/6e045b5f-b709-49a1-9422-5c5bb8ffb8ef%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 12:56am UTC](https://discuss.elastic.co/t/query-problem-with-nested-fields-using-dsl-with-elasticsearch/20262/3 "2017-07-06T00:56:07Z")

</div>


