# Possible optimisations for large \_source documents

**URL:** <https://discuss.elastic.co/t/possible-optimisations-for-large--source-documents/38987>\
**Category:** Elasticsearch\
**Created:** [January 12, 2016, 2:00pm UTC](https://discuss.elastic.co/t/possible-optimisations-for-large--source-documents/38987 "2016-01-12T14:00:13Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![yanns](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yanns/32/7094_2.png) [@yanns](https://discuss.elastic.co/u/yanns)\
**Post date:** [January 12, 2016, 2:00pm UTC](https://discuss.elastic.co/t/possible-optimisations-for-large--source-documents/38987/1 "2016-01-12T14:00:13Z")

</div>

Hi!

For a query, I observe a performance difference if I include or not the \_source.  
With: "\_source": true, the query needs about 250 ms to complete.  
With: "\_source": false, the query needs about 50 ms to complete.

In the mapping, I already disabled the \_all.  
I search about how to optimise this use-case and could not found any interesting information.

If you have any tips:

- about a possible configuration (disk, kernel, JVM...)
- about how to work-around this.

For example, has anybody tried to put the JSON as a String into one field, like `{"json": "<the json of the document>"}`?

Thanks in advance for any pointers,  
Yann

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 12, 2016, 2:27pm UTC](https://discuss.elastic.co/t/possible-optimisations-for-large--source-documents/38987/2 "2016-01-12T14:27:40Z")

</div>

Note that you can still store the `_source` field but when you query, you can ask for other fields but `_source`.

---

<div class="post-metadata">

**Author:** ![colings86](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colings86/32/44960_2.png) [@colings86](https://discuss.elastic.co/u/colings86)\
**Post date:** [January 12, 2016, 2:37pm UTC](https://discuss.elastic.co/t/possible-optimisations-for-large--source-documents/38987/3 "2016-01-12T14:37:21Z")

</div>

The JSON of the indexed document is already stored in a single field (called `_source`) . A couple of questions about your use case:

- How many documents are you retrieving? (Maybe you could share you whole search request?)
- How much memory have you allowed for the FileSystem Cache?

---

<div class="post-metadata">

**Author:** ![yanns](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yanns/32/7094_2.png) [@yanns](https://discuss.elastic.co/u/yanns)\
**Post date:** [January 12, 2016, 4:01pm UTC](https://discuss.elastic.co/t/possible-optimisations-for-large--source-documents/38987/4 "2016-01-12T16:01:54Z")

</div>

yes thx! I know that already.  
In that case, I'm interested in the whole `_source`.

---

<div class="post-metadata">

**Author:** ![yanns](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yanns/32/7094_2.png) [@yanns](https://discuss.elastic.co/u/yanns)\
**Post date:** [January 12, 2016, 4:07pm UTC](https://discuss.elastic.co/t/possible-optimisations-for-large--source-documents/38987/5 "2016-01-12T16:07:17Z")

</div>

> [@colings86](#):
>
> FileSystem Cache

Yes I am speaking exactly about this single field `_source`. When I deactive the retrieving of `_source` in the query results, I observe this difference of performance.  
I am retrieving 20 documents.

I am not sure about what you ask precisely with FileSystem Cache. The `free` command outputs:

```auto
$ free
             total used free shared buffers cached
Mem: 15396852 12732848 2664004 4296 153104 3033332

```

---

<div class="post-metadata">

**Author:** ![yanns](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yanns/32/7094_2.png) [@yanns](https://discuss.elastic.co/u/yanns)\
**Post date:** [January 12, 2016, 4:07pm UTC](https://discuss.elastic.co/t/possible-optimisations-for-large--source-documents/38987/6 "2016-01-12T16:07:59Z")

</div>

I'll try to compress the http responses to check if it makes a difference.  
If you have any other idea, feel free to suggest. Thx!

---

<div class="post-metadata">

**Author:** ![cheapsteak](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cheapsteak/32/17313_2.png) [@cheapsteak](https://discuss.elastic.co/u/cheapsteak)\
**Post date:** [April 12, 2017, 7:50pm UTC](https://discuss.elastic.co/t/possible-optimisations-for-large--source-documents/38987/7 "2017-04-12T19:50:26Z")

</div>

We're running into the same problem, when including `_source`, it takes 2+ seconds for a size of 50, when `_source` is false it takes 400ms

This is our query

```
GET /case_centric/case_centric/_search?pretty
{
  "size": 50,
  "from": 0,

  "_source": {
    "includes": ["diagnoses.days_to_last_follow_up"]
  },
  
  "query": {
    "bool": {
      "filter": [
        {
          "nested": {
            "path": "diagnoses",
            "query": {
              "bool": {
                "must": [
                  {
                    "exists": {
                      "field": "diagnoses.vital_status"
                    }
                  }
                ]
              }
            }
          }
        }
      ],
      "should": [
        {
          "bool": {
            "should": [
              {
                "nested": {
                  "path": "diagnoses",
                  "query": {
                    "bool": {
                      "must": [
                        {
                          "exists": {
                            "field": "diagnoses.days_to_death"
                          }
                        }
                      ]
                    }
                  }
                }
              },
              {
                "nested": {
                  "path": "diagnoses",
                  "query": {
                    "bool": {
                      "must": [
                        {
                          "exists": {
                            "field": "diagnoses.days_to_last_follow_up"
                          }
                        }
                      ]
                    }
                  }
                }
              }
            ]
          }
        }
      ]
    }
  }
}
```

---

<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, 10:01pm UTC](https://discuss.elastic.co/t/possible-optimisations-for-large--source-documents/38987/8 "2017-07-05T22:01:14Z")

</div>


