# Exists Query for Object type

**URL:** <https://discuss.elastic.co/t/exists-query-for-object-type/109832>\
**Category:** Elasticsearch\
**Created:** [November 30, 2017, 8:41pm UTC](https://discuss.elastic.co/t/exists-query-for-object-type/109832 "2017-11-30T20:41:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![fpillo](https://avatars.discourse-cdn.com/v4/letter/f/91b2a8/32.png) [@fpillo](https://discuss.elastic.co/u/fpillo)\
**Post date:** [November 30, 2017, 8:41pm UTC](https://discuss.elastic.co/t/exists-query-for-object-type/109832/1 "2017-11-30T20:41:02Z")

</div>

Hi guys, I know that for execute a "exists" query in a nested type I could use a nested query.  
But how about simple Object type?

I am doing this:

{  
"from" : 0,  
"size" : 10,  
"query" : {  
"bool" : {  
"must" : [  
{  
"match\_all" : {  
}  
},  
{  
"exists" : { "field" : "object\_type\_field" }  
}  
]  
}  
}  
}

---

<div class="post-metadata">

**Author:** ![JKhondhu](https://avatars.discourse-cdn.com/v4/letter/j/ed655f/32.png) [@JKhondhu](https://discuss.elastic.co/u/JKhondhu)\
**Post date:** [November 30, 2017, 11:50pm UTC](https://discuss.elastic.co/t/exists-query-for-object-type/109832/2 "2017-11-30T23:50:42Z")

</div>

Hi,  
Would a must match work? See here: [https://www.elastic.co/guide/en/elasticsearch/guide/master/nested-query.html](https://www.elastic.co/guide/en/elasticsearch/guide/master/nested-query.html)

---

<div class="post-metadata">

**Author:** ![fpillo](https://avatars.discourse-cdn.com/v4/letter/f/91b2a8/32.png) [@fpillo](https://discuss.elastic.co/u/fpillo)\
**Post date:** [December 1, 2017, 10:52am UTC](https://discuss.elastic.co/t/exists-query-for-object-type/109832/3 "2017-12-01T10:52:10Z")

</div>

No, because the field is not a nested type ☹

"caused\_by": {  
"type": "illegal\_state\_exception",  
"reason": "[nested] nested object under path [item\_availability\_hours] is not of nested type"  
}

here is the field:

```
{
    "properties": {
      "item_availability_hours": {
        "properties": {
          "FRIDAY": {
            "type": "nested",
            "properties": {
              "end": {
                "type": "date",
                "format": "hour_minute_second"
              },
              "start": {
                "type": "date",
                "format": "hour_minute_second"
              }
            }
          },
          "MONDAY": {
            "type": "nested",
            "properties": {
              "end": {
                "type": "date",
                "format": "hour_minute_second"
              },
              "start": {
                "type": "date",
                "format": "hour_minute_second"
              }
            }
          },
          "SATURDAY": {
            "type": "nested",
            "properties": {
              "end": {
                "type": "date",
                "format": "hour_minute_second"
              },
              "start": {
                "type": "date",
                "format": "hour_minute_second"
              }
            }
          },
          "SUNDAY": {
            "type": "nested",
            "properties": {
              "end": {
                "type": "date",
                "format": "hour_minute_second"
              },
              "start": {
                "type": "date",
                "format": "hour_minute_second"
              }
            }
          },
          "THURSDAY": {
            "type": "nested",
            "properties": {
              "end": {
                "type": "date",
                "format": "hour_minute_second"
              },
              "start": {
                "type": "date",
                "format": "hour_minute_second"
              }
            }
          },
          "TUESDAY": {
            "type": "nested",
            "properties": {
              "end": {
                "type": "date",
                "format": "hour_minute_second"
              },
              "start": {
                "type": "date",
                "format": "hour_minute_second"
              }
            }
          },
          "WEDNESDAY": {
            "type": "nested",
            "properties": {
              "end": {
                "type": "date",
                "format": "hour_minute_second"
              },
              "start": {
                "type": "date",
                "format": "hour_minute_second"
              }
            }
          }
        }
      }
    }

```

}

---

<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:** [December 29, 2017, 10:52am UTC](https://discuss.elastic.co/t/exists-query-for-object-type/109832/4 "2017-12-29T10:52:10Z")

</div>

Closed on December 29, 2017, 10:52am UTC

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