# I cant search nested

**URL:** <https://discuss.elastic.co/t/i-cant-search-nested/339187>\
**Category:** Elasticsearch\
**Created:** [July 25, 2023, 12:05pm UTC](https://discuss.elastic.co/t/i-cant-search-nested/339187 "2023-07-25T12:05:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Murilo\_Livorato](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/murilo_livorato/32/123848_2.png) [@Murilo\_Livorato](https://discuss.elastic.co/u/Murilo_Livorato)\
**Post date:** [July 25, 2023, 12:05pm UTC](https://discuss.elastic.co/t/i-cant-search-nested/339187/1 "2023-07-25T12:05:25Z")

</div>

hello , I am trying to search nested .  
I dont know what I am doing wrong .

MY MAPPING

```auto
{
  "user-data-info": {
    "mappings": {
      "dynamic": "false",
      "properties": {
        "company": {
          "type": "nested"
        },
        "timestamp": {
          "type": "date",
          "format": "yyyy-MM-dd"
        }
      }
    }
  }
}

```

```auto
GET user-data-info/_search
{
  "query": {
    "match_all": {}
  }
}

```

RESULT - FOUND 1 RESULT

```auto
{
  "took": 0,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 1,
      "relation": "eq"
    },
    "max_score": 1,
    "hits": [
      {
        "_index": "user-data-info",
        "_id": "bb56iYkB8sgA-4K-OT_i",
        "_score": 1,
        "_source": {
          "timestamp": "2023-06-01",
          "company": {
            "id": 1,
            "name": "Nike"
          }
        }
      }
    ]
  }
}

```

SEACHING NESTED

```auto
GET /user-data-info/_search
{
  "query": {
    "nested": {
      "path": "company",
      "query": {
        "bool": {
          "must": [
            { "match": { "company.id": 1 } }
          ]
        }
      }
    }
  }
}

```

RESULT / FOUND 0

```auto
{
  "took": 0,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 0,
      "relation": "eq"
    },
    "max_score": null,
    "hits": []
  }
}

```

---

<div class="post-metadata">

**Author:** ![Kathleen\_DeRusso](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kathleen_derusso/32/132039_2.png) [@Kathleen\_DeRusso](https://discuss.elastic.co/u/Kathleen_DeRusso)\
**Post date:** [July 25, 2023, 12:45pm UTC](https://discuss.elastic.co/t/i-cant-search-nested/339187/2 "2023-07-25T12:45:59Z")

</div>

Hi @Murilo_Livorato,

The nested query that you're sending in looks right.

I duplicated the example that you gave, but my mappings looked a bit different from yours:

```auto
PUT /user-data-info/_mapping
{
  "properties": {
    "company": {
      "type": "nested"
    },
    "timestamp": {
      "type": "date",
      "format": "yyyy-MM-dd"
    }
  }
}

```

Using this mapping, and the following document:

```auto
POST user-data-info/_doc/1
{
  "company": {
    "id": 1,
    "name": "nike"
  }
}

```

The nested query you posted should work. Perhaps you can look at your index mappings and settings and make sure that it's correct?

Good luck!

---

<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:** [July 25, 2023, 12:49pm UTC](https://discuss.elastic.co/t/i-cant-search-nested/339187/3 "2023-07-25T12:49:44Z")

</div>

I'm not sure that this really qualifies for nested docs:

```auto
{
  "timestamp": "2023-06-01",
  "company": {
    "id": 1,
    "name": "Nike"
  }
}

```

I'd do instead:

```auto
{
  "timestamp": "2023-06-01",
  "company": [{
    "id": 1,
    "name": "Nike"
  }]
}

```

---

<div class="post-metadata">

**Author:** ![Murilo\_Livorato](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/murilo_livorato/32/123848_2.png) [@Murilo\_Livorato](https://discuss.elastic.co/u/Murilo_Livorato)\
**Post date:** [July 25, 2023, 12:52pm UTC](https://discuss.elastic.co/t/i-cant-search-nested/339187/4 "2023-07-25T12:52:16Z")

</div>

I changed this field , and it worked -

```auto
"dynamic": "true " 

```

---

<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 22, 2023, 12:52pm UTC](https://discuss.elastic.co/t/i-cant-search-nested/339187/5 "2023-08-22T12:52:44Z")

</div>

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