# Trouble to understand some simple query

**URL:** <https://discuss.elastic.co/t/trouble-to-understand-some-simple-query/217387>\
**Category:** Elasticsearch\
**Created:** [January 31, 2020, 1:46pm UTC](https://discuss.elastic.co/t/trouble-to-understand-some-simple-query/217387 "2020-01-31T13:46:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Guss4241](https://avatars.discourse-cdn.com/v4/letter/g/34f0e0/32.png) [@Guss4241](https://discuss.elastic.co/u/Guss4241)\
**Post date:** [January 31, 2020, 1:46pm UTC](https://discuss.elastic.co/t/trouble-to-understand-some-simple-query/217387/1 "2020-01-31T13:46:06Z")

</div>

Hi,

i'm working with elasticsearch since some weeks now and I'm on the final step for my company project, but I have have some trouble to understand a trouble with a simple query.

in my index I have a nested field call "simulateur" which on conatins a "prettyName" and a "reference" field.

to filter my result I use this nested query for example:

```auto
              {
                "nested": {
                  "path": "simulateur",
                  "query": {
                    "query_string": {
                      "query": "BAT-EN-106",
                      "analyzer": "keyword",
                      "fields": [
                        "simulateur.reference"
                      ]
                    }
                  }
                }
              }

```

this one return me 0 result but I have an entry that must match the request:

```auto
{
  "took" : 32,
  "timed_out" : false,
  "_shards" : {
    "total" : 4,
    "successful" : 4,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 1,
    "max_score" : null,
    "hits" : [
      {
        "_index" : "app_op_prod_2020-01-30-174513",
        "_type" : "offre_projet",
        "_id" : "56482",
        "_score" : null,
        "_source" : {
          ...
          "simulateur" : {
            "prettyName" : "Isolation des combles ou de toitures (Outremer TERTIAIRE)",
            "reference" : "BAT-EN-106"
          },
         ...
        },
        "sort" : [
          1573663408000
        ]
      }
    ]
  }
}

```

I don't understand why I have no result when I use the nested query.  
if you need more information to be able to help me just ask.

I use elasticsearch 6.8  
thanks in advance for those who will try to help me.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 31, 2020, 1:57pm UTC](https://discuss.elastic.co/t/trouble-to-understand-some-simple-query/217387/2 "2020-01-31T13:57:35Z")

</div>

Could you provide a full recreation script as described in [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

---

<div class="post-metadata">

**Author:** ![Guss4241](https://avatars.discourse-cdn.com/v4/letter/g/34f0e0/32.png) [@Guss4241](https://discuss.elastic.co/u/Guss4241)\
**Post date:** [January 31, 2020, 2:25pm UTC](https://discuss.elastic.co/t/trouble-to-understand-some-simple-query/217387/3 "2020-01-31T14:25:25Z")

</div>

I will give a try as my index is generated with elastica from a sql database.

```auto
DELETE index
PUT index/_doc/1
{
  "reference": "XXX00001",
  "simulateur": {
    "prettyName": "Isolation des combles",
    "reference": "BAT-EN-106"
  }
}
GET index/_search
{
  "query": {
    "nested": {
      "path": "simulateur",
      "query": {
        "query_string": {
          "query": "BAT-EN-106",
          "analyzer": "keyword",
          "fields": [
            "simulateur.reference"
          ]
        }
      }
    }
  }
}

```

I can provide my elastica configuration if it's can help a bit more.

---

<div class="post-metadata">

**Author:** ![Guss4241](https://avatars.discourse-cdn.com/v4/letter/g/34f0e0/32.png) [@Guss4241](https://discuss.elastic.co/u/Guss4241)\
**Post date:** [January 31, 2020, 3:49pm UTC](https://discuss.elastic.co/t/trouble-to-understand-some-simple-query/217387/4 "2020-01-31T15:49:54Z")

</div>

I found a solution by getting back to standard analizer with `default_operator` set to `AND`

here the nest query part:

```auto
{
                "nested": {
                  "path": "simulateur",
                  "query": {
                    "query_string": {
                      "query": "BAT-EN-106",
                      "default_operator": "AND",
                      "fields": [
                        "simulateur.reference"
                      ]
                    }
                  }
                }
              }

```

---

<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:** [February 28, 2020, 3:50pm UTC](https://discuss.elastic.co/t/trouble-to-understand-some-simple-query/217387/5 "2020-02-28T15:50:02Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
