# Query not returning null / field that does not exist

**URL:** <https://discuss.elastic.co/t/query-not-returning-null-field-that-does-not-exist/32130>\
**Category:** Elasticsearch\
**Created:** [October 14, 2015, 12:29am UTC](https://discuss.elastic.co/t/query-not-returning-null-field-that-does-not-exist/32130 "2015-10-14T00:29:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ScienceFiction](https://avatars.discourse-cdn.com/v4/letter/s/c5a1d2/32.png) [@ScienceFiction](https://discuss.elastic.co/u/ScienceFiction)\
**Post date:** [October 14, 2015, 12:29am UTC](https://discuss.elastic.co/t/query-not-returning-null-field-that-does-not-exist/32130/1 "2015-10-14T00:29:55Z")

</div>

I have a certain field which can be null, as I understand Elastic will not store this value anywhere in the Index since it is null.

However the problem I have is when doing a query and specifically a nested query I am not getting the desired results.

Take the below returned fields as an example:

```
           "attachments.id": [
              2,
              5,
              1,
              4,
              0,
              3
           ],
           "attachments.parentId": [
              2,
              1,
              0
           ]

```

The issue I face is that I can not match the attachments.ids with the parentIds. Only child attachments have a parent. If there was a way to return nulls or even a default value I would know which nodes are parent nodes (because their parentId would be null or -1).

I though I could achieve this by setting the "allow\_null" value to -1 in the mapping for the attachments.parentId field but this did nothing...

To summarize I want to be able to say the parentId of this attachmentId is XX (whether that be 1,2,3 or -1).

Any suggestions?

---

<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:** [July 5, 2017, 11:44pm UTC](https://discuss.elastic.co/t/query-not-returning-null-field-that-does-not-exist/32130/2 "2017-07-05T23:44:59Z")

</div>


