# Can I use comments in JSON request to ES?

**URL:** <https://discuss.elastic.co/t/can-i-use-comments-in-json-request-to-es/100312>\
**Category:** Elasticsearch\
**Created:** [September 13, 2017, 8:31am UTC](https://discuss.elastic.co/t/can-i-use-comments-in-json-request-to-es/100312 "2017-09-13T08:31:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Freyja](https://avatars.discourse-cdn.com/v4/letter/f/3da27b/32.png) [@Freyja](https://discuss.elastic.co/u/Freyja)\
**Post date:** [September 13, 2017, 8:31am UTC](https://discuss.elastic.co/t/can-i-use-comments-in-json-request-to-es/100312/1 "2017-09-13T08:31:24Z")

</div>

I created a quite complicated request to ES (I send it via curl), so I wanted to add a bit of documentation to it. I read that JSON does not allow comments, but I put a comment of type /\* ... \*/ inside the request and it succeeded. Can I assume that ES allows such comments inside JSON request?

I'm currently using ES 2.4.2, but I'm more interested if current and future versions will allow comments.

Or maybe I can send requests in other languages, for example YAML, that allows comments?

I'm aware that I can use some tool to remove comments before I send it to ES, but I wanted to get sure if I really need to do this.

My request looks like this (it does not make much sense because you can use avg metric instead).

```
{
	"query" : 
	{
		"match_all" : {}
	},
	"aggregations": 
	{
		"avg_score": 
		{
			"scripted_metric": 
			{
				"init_script" : 
				/* comment */
					"_agg['scores'] = []; _agg['count'] = 0",
				"map_script" : 
					"_agg.scores.add(doc['score'].value); _agg.count += 1",
				"combine_script" : 
					"sum = 0; for (s in _agg.scores) { sum += s }; return [sum, _agg.count]",
				"reduce_script" : 
					"avg_sum = 0; avg_count = 0; for (a in _aggs) { avg_sum += a[0]; avg_count += a[1]; }; return avg_sum / avg_count"
			}
		}
	}
}
```

---

<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:** [September 13, 2017, 8:51am UTC](https://discuss.elastic.co/t/can-i-use-comments-in-json-request-to-es/100312/2 "2017-09-13T08:51:03Z")

</div>

I would not assume that Elasticsearch allows comments inside JSON requests. As you mentioned, the JSON spec does not allow comments and I am surprised that it worked in your test to be honest. Its not something that is tested and not something we explicitly support so it could stop working at any time.

---

<div class="post-metadata">

**Author:** ![Freyja](https://avatars.discourse-cdn.com/v4/letter/f/3da27b/32.png) [@Freyja](https://discuss.elastic.co/u/Freyja)\
**Post date:** [September 13, 2017, 11:12am UTC](https://discuss.elastic.co/t/can-i-use-comments-in-json-request-to-es/100312/3 "2017-09-13T11:12:05Z")

</div>

Thank you for the quick answer and the explanation.

---

<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:** [October 11, 2017, 11:12am UTC](https://discuss.elastic.co/t/can-i-use-comments-in-json-request-to-es/100312/4 "2017-10-11T11:12:07Z")

</div>

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