# Simple query string, default operator and, doesn't work with nested objects

**URL:** <https://discuss.elastic.co/t/simple-query-string-default-operator-and-doesnt-work-with-nested-objects/240426>\
**Category:** Elasticsearch\
**Created:** [July 8, 2020, 7:46pm UTC](https://discuss.elastic.co/t/simple-query-string-default-operator-and-doesnt-work-with-nested-objects/240426 "2020-07-08T19:46:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pilo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pilo/32/46015_2.png) [@pilo](https://discuss.elastic.co/u/pilo)\
**Post date:** [July 8, 2020, 7:46pm UTC](https://discuss.elastic.co/t/simple-query-string-default-operator-and-doesnt-work-with-nested-objects/240426/1 "2020-07-08T19:46:36Z")

</div>

Hello everyone, as mentioned in the title, seem like `simple_query_string` with default operator `and` doesn't work with nested data type.

For example, i have a mapping like bellow:

```auto
PUT test1
{
  "mappings": {
    "properties": {
      "nested_articles" : {
          "type" : "nested",
          "properties" : {
            "article_title" : {
              "properties" : {
                "en" : {
                  "type" : "keyword",
                  "fields" : {
                    "default" : {
                      "type" : "text",
                      "term_vector" : "with_positions_offsets",
                      "analyzer" : "english"
                    },
                    "exact" : {
                      "type" : "text",
                      "term_vector" : "with_positions_offsets",
                      "analyzer" : "english_exact"
                    }
                  },
                  "ignore_above" : 20
                }
              }
            },
            "content" : {
              "properties" : {
                "en" : {
                  "type" : "keyword",
                  "fields" : {
                    "default" : {
                      "type" : "text",
                      "term_vector" : "with_positions_offsets",
                      "analyzer" : "english"
                    },
                    "exact" : {
                      "type" : "text",
                      "term_vector" : "with_positions_offsets",
                      "analyzer" : "english_exact"
                    }
                  },
                  "ignore_above" : 20
                }
              }
            }
          }
        }
    }
  }
}

```

As you can see, `nested_articles` with type nested has two fields `articles_title` and `content`. Each field has two analyzers "default" (for stemming) et "exact" (pour exact search). I added a document like this:

```auto
PUT test1/_doc/1
{
  "nested_articles" : [
    {
      "article_title" : {
        "en": "John"
      },
      "content" : {
        "en": "Smith"
      }
    },
    {
      "article_title" : {
        "en": "foo"
      },
      "content" : {
        "en": "bar"
      }
    }
  ]
}

```

Problem come when i use `simple_query_string`

```auto
GET test1/_search
{
  "query": {
    "nested": {
      "path": "nested_articles",
      "query": {
        "simple_query_string": {
          "query": "smith bar",
          "fields": [
            "nested_articles.article_title.en.default^3",
            "nested_articles.content.en.default"
          ],
          "default_operator": "and"
        }
      }
    }
  }
}

```

I'm looking for the documents with two words "smith" and "bar", in any field but i have no result here. However, if i search for the words in the same objet (for example, `John Smith` with `John` in `articles` and `Smith` in `content`), It works like charm.  
Do you have any solution (query or mapping) that can work with simple\_query\_string, default operator and ?  
Thank you all.

---

<div class="post-metadata">

**Author:** ![pilo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pilo/32/46015_2.png) [@pilo](https://discuss.elastic.co/u/pilo)\
**Post date:** [July 8, 2020, 7:48pm UTC](https://discuss.elastic.co/t/simple-query-string-default-operator-and-doesnt-work-with-nested-objects/240426/2 "2020-07-08T19:48:36Z")

</div>

After work around, i have one solution that use `include_in_root` and launch `simple_query_string` in this field. However, this solution doesn't keep the relation between `articles` and `contents`. In our usecase, this relation is really important.  
Do you have any better solution?  
Thank you all.

---

<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:** [August 5, 2020, 7:48pm UTC](https://discuss.elastic.co/t/simple-query-string-default-operator-and-doesnt-work-with-nested-objects/240426/3 "2020-08-05T19:48:39Z")

</div>

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