# Best practice for empty fields?

**URL:** https://discuss.elastic.co/t/best-practice-for-empty-fields/132411
**Category:** Elasticsearch
**Created:** [May 18, 2018, 3:49am UTC](https://discuss.elastic.co/t/best-practice-for-empty-fields/132411 "2018-05-18T03:49:26Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![spynxo](https://avatars.discourse-cdn.com/v4/letter/s/b77776/32.png) [@spynxo](https://discuss.elastic.co/u/spynxo)
#### Post date: [May 18, 2018, 3:49am UTC](https://discuss.elastic.co/t/best-practice-for-empty-fields/132411/1 "2018-05-18T03:49:26Z")

</div>

Hi All,

For empty fields, should I use `null` or `""`? What is the best practice? Are they equivalent?

Thanks!

---

<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: [May 18, 2018, 7:51am UTC](https://discuss.elastic.co/t/best-practice-for-empty-fields/132411/2 "2018-05-18T07:51:59Z")

</div>

can you share more context, perhaps even screenshots?

---

<div class="post-metadata">

### Author: ![spynxo](https://avatars.discourse-cdn.com/v4/letter/s/b77776/32.png) [@spynxo](https://discuss.elastic.co/u/spynxo)
#### Post date: [May 18, 2018, 2:26pm UTC](https://discuss.elastic.co/t/best-practice-for-empty-fields/132411/3 "2018-05-18T14:26:59Z")

</div>

Sure! For example, lets say that I have an index with user information. There is a field for age (type long). There could be cases where the age is not known. Which value should I use for the age field when inserting the record (`null` or `""`)? They both seem to work. I am wondering which one would be better.

```auto
PUT users/_doc/1
{
    "user": "kimchy",
    "age": ""
}

```

vs

```auto
PUT users/_doc/1
{
    "user": "kimchy",
    "age": null
}

```

---

<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: [May 18, 2018, 2:55pm UTC](https://discuss.elastic.co/t/best-practice-for-empty-fields/132411/4 "2018-05-18T14:55:22Z")

</div>

> [@spynxo](#):
>
> PUT users/\_doc/1  
> {  
> "user": "kimchy",  
> "age": ""  
> }

👍

---

<div class="post-metadata">

### Author: ![Gilad\_Sh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gilad_sh/32/31564_2.png) [@Gilad\_Sh](https://discuss.elastic.co/u/Gilad_Sh)
#### Post date: [May 24, 2018, 10:39am UTC](https://discuss.elastic.co/t/best-practice-for-empty-fields/132411/5 "2018-05-24T10:39:30Z")

</div>

Can you please explain why this is better?  
Will it help with better performance in queries?  
How about other options as not adding this field at all or some default value (e.g.: -1) ?

---

<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: [June 21, 2018, 10:39am UTC](https://discuss.elastic.co/t/best-practice-for-empty-fields/132411/6 "2018-06-21T10:39:33Z")

</div>

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