# Potential issue with bool and nested term

**URL:** https://discuss.elastic.co/t/potential-issue-with-bool-and-nested-term/204413
**Category:** Elasticsearch
**Created:** [October 21, 2019, 8:31am UTC](https://discuss.elastic.co/t/potential-issue-with-bool-and-nested-term/204413 "2019-10-21T08:31:00Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Spansh](https://avatars.discourse-cdn.com/v4/letter/s/bc8723/32.png) [@Spansh](https://discuss.elastic.co/u/Spansh)
#### Post date: [October 21, 2019, 8:31am UTC](https://discuss.elastic.co/t/potential-issue-with-bool-and-nested-term/204413/1 "2019-10-21T08:31:00Z")

</div>

I think I have found an issue with arrays of nested fields and bool matching.

I have a nested field which has multiple values where I want to search for records which have multiple values within it. If I search for a single value, it works fine. If I search for multiple values it does not.

I think I've created a somewhat minimal test case below.

```auto
curl -X PUT "localhost:9200/nested_bool?pretty=true&refresh=true" -H 'Content-Type: application/json' -d'
{
    "mappings": {
        "properties": {
            "export_commodities": {
                "type": "nested",
                "properties": {
                    "name": { "type": "text", "fields": { "keyword": { "type": "keyword" } } }
                }
            }
        }
    }
}
'

curl -X POST "localhost:9200/nested_bool/_doc/?pretty" -H 'Content-Type: application/json' -d'
{
    "export_commodities" : [{"name": "Hydrogen Fuel"},{"name": "Animal Monitors"}]
}
'

curl -X POST "localhost:9200/nested_bool/_doc/?pretty" -H 'Content-Type: application/json' -d'
{
    "export_commodities" : [{"name": "Hydrogen Fuel"},{"name": "Biowaste"}]
}
'

curl -X POST "localhost:9200/nested_bool/_doc/?pretty" -H 'Content-Type: application/json' -d'
{
    "export_commodities" : {"name":" Biowaste"}
}
'

curl -X POST "localhost:9200/nested_bool/_doc/?pretty" -H 'Content-Type: application/json' -d'
{
    "export_commodities" : [{"name": "Platinum"},{"name": "Animal Monitors"}]
}
'

```

This search returns nothing

```auto
curl -H 'Content-Type: application/json' -X GET "http://localhost:9200/nested_bool/_search?pretty=true&size=10" -d '
{
    "query": {
        "nested": {
            "path": "export_commodities",
            "query": {
                "bool": {
                    "filter": [
                        {
                            "term": {
                                "export_commodities.name.keyword": "Animal Monitors"
                            }
                        },
                        {
                            "term": {
                                "export_commodities.name.keyword": "Hydrogen Fuel"
                            }
                        }
                    ]
                }
            }
        }
    }
}
'

```

This search returns as expected

```auto
curl -H 'Content-Type: application/json' -X GET "http://localhost:9200/nested_bool/_search?pretty=true&size=10" -d '
{
    "query": {
        "nested": {
            "path": "export_commodities",
            "query": {
                "bool": {
                    "filter": [
                        {
                            "term": {
                                "export_commodities.name.keyword": "Hydrogen Fuel"
                            }
                        }
                    ]
                }
            }
        }
    }
}
'

```

I'm happy to register an issue on github, but I thought it would be best to ask here first in case I've missed something really obvious.

---

<div class="post-metadata">

### Author: ![Glen\_Smith](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/glen_smith/32/111656_2.png) [@Glen\_Smith](https://discuss.elastic.co/u/Glen_Smith)
#### Post date: [October 21, 2019, 7:55pm UTC](https://discuss.elastic.co/t/potential-issue-with-bool-and-nested-term/204413/2 "2019-10-21T19:55:23Z")

</div>

Try this instead:

```auto
GET /nested_bool/_search
{
  "query": {
    "bool": {
      "filter": [
        {
          "nested": {
            "path": "export_commodities",
            "query": {
              "term": {
                "export_commodities.name.keyword": "Animal Monitors"
              }
            }
          }
        },
        {
          "nested": {
            "path": "export_commodities",
            "query": {
              "term": {
                "export_commodities.name.keyword": "Hydrogen Fuel"
              }
            }
          }
        }
      ]
    }
  }
}

```

---

<div class="post-metadata">

### Author: ![Spansh](https://avatars.discourse-cdn.com/v4/letter/s/bc8723/32.png) [@Spansh](https://discuss.elastic.co/u/Spansh)
#### Post date: [October 22, 2019, 7:58am UTC](https://discuss.elastic.co/t/potential-issue-with-bool-and-nested-term/204413/3 "2019-10-22T07:58:52Z")

</div>

Yep that works, a little counter intuitive since the singular works but at least I can get around it. Is it worth registering an issue on github about it or is it "working as intended"?

---

<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: [November 19, 2019, 7:58am UTC](https://discuss.elastic.co/t/potential-issue-with-bool-and-nested-term/204413/4 "2019-11-19T07:58:58Z")

</div>

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