# Querying attachment arrays \[ingest mapper plugin\]

**URL:** <https://discuss.elastic.co/t/querying-attachment-arrays-ingest-mapper-plugin/74269>\
**Category:** Elasticsearch\
**Created:** [February 7, 2017, 6:58pm UTC](https://discuss.elastic.co/t/querying-attachment-arrays-ingest-mapper-plugin/74269 "2017-02-07T18:58:27Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![tlovett1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tlovett1/32/13950_2.png) [@tlovett1](https://discuss.elastic.co/u/tlovett1)\
**Post date:** [February 7, 2017, 6:58pm UTC](https://discuss.elastic.co/t/querying-attachment-arrays-ingest-mapper-plugin/74269/1 "2017-02-07T18:58:27Z")

</div>

Hello,

In [this example](https://www.elastic.co/guide/en/elasticsearch/plugins/master/ingest-attachment-with-arrays.html), how can I search the nested attachments? A simple example would be super helpful.

I am trying something like this but getting a nested object error:

```
{
  "query": {
    "bool": {
      "must": [
        {
          "nested": {
            "path": "attachments",
            "query": {
              "bool": {
                "must": [
                  {
                    "match": {
                      "attachments.content": "search text"
                    }
                  }
                ]
              }
            }
          }
        }
      ]
    }
  }
}
```

---

<div class="post-metadata">

**Author:** ![tlovett1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tlovett1/32/13950_2.png) [@tlovett1](https://discuss.elastic.co/u/tlovett1)\
**Post date:** [February 8, 2017, 5:21pm UTC](https://discuss.elastic.co/t/querying-attachment-arrays-ingest-mapper-plugin/74269/2 "2017-02-08T17:21:58Z")

</div>

Anyone?

---

<div class="post-metadata">

**Author:** ![rshake](https://avatars.discourse-cdn.com/v4/letter/r/41988e/32.png) [@rshake](https://discuss.elastic.co/u/rshake)\
**Post date:** [February 8, 2017, 11:13pm UTC](https://discuss.elastic.co/t/querying-attachment-arrays-ingest-mapper-plugin/74269/3 "2017-02-08T23:13:33Z")

</div>

You ought to be able to pull a document containing an attachment to see the actual structure.

```
GET http://yourElasticSearchURL:9200/index/type/ID

```

What I think may be going on is that the ingest plugin actually creates another nested object inside your attachments object.

So, your match statement would need to be:  
"attachments.attachment.content": "search text"

Does that make sense?

---

<div class="post-metadata">

**Author:** ![tlovett1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tlovett1/32/13950_2.png) [@tlovett1](https://discuss.elastic.co/u/tlovett1)\
**Post date:** [February 9, 2017, 8:18pm UTC](https://discuss.elastic.co/t/querying-attachment-arrays-ingest-mapper-plugin/74269/4 "2017-02-09T20:18:40Z")

</div>

That doesn't work 😕

---

<div class="post-metadata">

**Author:** ![rshake](https://avatars.discourse-cdn.com/v4/letter/r/41988e/32.png) [@rshake](https://discuss.elastic.co/u/rshake)\
**Post date:** [February 9, 2017, 8:21pm UTC](https://discuss.elastic.co/t/querying-attachment-arrays-ingest-mapper-plugin/74269/5 "2017-02-09T20:21:03Z")

</div>

Can you post a document you pull from your index? That would help in determining what the actual structure is and what the query needs to look like.

---

<div class="post-metadata">

**Author:** ![tlovett1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tlovett1/32/13950_2.png) [@tlovett1](https://discuss.elastic.co/u/tlovett1)\
**Post date:** [February 9, 2017, 8:26pm UTC](https://discuss.elastic.co/t/querying-attachment-arrays-ingest-mapper-plugin/74269/6 "2017-02-09T20:26:13Z")

</div>

Here's a document:

```
{
    "_index": "localhost-1",
    "_type": "post",
    "_id": "496",
    "_score": 1,
    "_source": {
        "comment_count": 0,
        "post_title": ".....",
        "post_author": {
            "raw": "admin",
            "id": 1,
            "login": "admin",
            "display_name": "admin"
        },
        "menu_order": 0,
        "attachments": [
            {
                "data": "........",
                "attachment": {
                    "date": "2017-01-05T18:47:15Z",
                    "content_type": "application/pdf",
                    "author": "....",
                    "language": "en",
                    "content": "........",
                    "content_length": 3373
                }
            }
        ],
        "post_excerpt": "",
        "post_mime_type": "application/pdf",
        "post_name": "......",
        "terms": [],
        "post_modified": "2017-02-07 14:55:06",
        "post_type": "attachment",
        "ID": 496,
        "post_status": "inherit",
        "post_meta": [],
        "date_terms": {
            "week": 6,
            "dayofweek_iso": 2,
            "month": 2,
            "hour": 14,
            "year": 2017,
            "dayofweek": 2,
            "day": 7,
            "m": 201702,
            "dayofyear": 37,
            "minute": 55,
            "second": 6
        },
        "post_date_gmt": "2017-02-07 14:55:06",
        "post_modified_gmt": "2017-02-07 14:55:06",
        "comment_status": 0,
        "post_parent": 493,
        "post_content": "....",
        "ping_status": 0,
        "post_id": 496,
        "post_date": "2017-02-07 14:55:06",
        "meta": [],
        "guid": "...",
        "permalink": "..."
    }
}
```

---

<div class="post-metadata">

**Author:** ![tlovett1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tlovett1/32/13950_2.png) [@tlovett1](https://discuss.elastic.co/u/tlovett1)\
**Post date:** [February 9, 2017, 8:29pm UTC](https://discuss.elastic.co/t/querying-attachment-arrays-ingest-mapper-plugin/74269/7 "2017-02-09T20:29:27Z")

</div>

Given that I'm getting the error "[nested] nested object under path [attachments] is not of nested type", it seems like a nested query is completely wrong.

---

<div class="post-metadata">

**Author:** ![rshake](https://avatars.discourse-cdn.com/v4/letter/r/41988e/32.png) [@rshake](https://discuss.elastic.co/u/rshake)\
**Post date:** [February 9, 2017, 8:32pm UTC](https://discuss.elastic.co/t/querying-attachment-arrays-ingest-mapper-plugin/74269/8 "2017-02-09T20:32:06Z")

</div>

Ah - I'm a bit slow (and really new to elasticSearch). I think you're right.

Did you explicitly set a mapping for this index/type? And did you define your attachments property as a nested object? If not, that would be why the nested query is not happy.

---

<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:** [March 9, 2017, 8:32pm UTC](https://discuss.elastic.co/t/querying-attachment-arrays-ingest-mapper-plugin/74269/9 "2017-03-09T20:32:12Z")

</div>

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