# Nested search works not as expected

**URL:** <https://discuss.elastic.co/t/nested-search-works-not-as-expected/311841>\
**Category:** Elasticsearch\
**Created:** [August 10, 2022, 2:17pm UTC](https://discuss.elastic.co/t/nested-search-works-not-as-expected/311841 "2022-08-10T14:17:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![wegad61878](https://avatars.discourse-cdn.com/v4/letter/w/f6c823/32.png) [@wegad61878](https://discuss.elastic.co/u/wegad61878)\
**Post date:** [August 10, 2022, 2:17pm UTC](https://discuss.elastic.co/t/nested-search-works-not-as-expected/311841/1 "2022-08-10T14:17:57Z")

</div>

Hello,

I have the following documents

```auto
[
  {
    "id": "Car#1",
    "accessories": [
      {
        "type": "Turbo",
        "price": 20
      },
      {
        "type": "Supercharger",
        "price": 30
      }
    ]
  },
  {
    "id": "Car#2",
    "accessories": [
      {
        "type": "Turbo",
        "price": 20
      }
    ]
  },
  {
    "id": "Car#3",
    "accessories": [
      {
        "type": "Supercharger",
        "price": 30
      }
    ]
  },
  {
    "id": "Car#4",
    "accessories": [
      {
        "type": "Turbo",
        "price": 10
      },
      {
        "type": "Supercharger",
        "price": 30
      }
    ]
  }
]

```

(accessories are nested)

I am trying to write a query that returns all cars that have "Supercharger" with price: 30 when "Turbo" is not price 20

The result given the test dataset should be: "Car#4", "Car#3"

These will not be included:  
("Car#2" does not have "Supercharger", "Car#1" has "Supercharger" however Turbo price is 20 and does not count)

1. Is this query possible?
2. Can you give an example query which works? I have tried for 2 weeks now and can't think of anything?

---

<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:** [September 7, 2022, 2:18pm UTC](https://discuss.elastic.co/t/nested-search-works-not-as-expected/311841/2 "2022-09-07T14:18:32Z")

</div>

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