# Reindexing from HTML

**URL:** <https://discuss.elastic.co/t/reindexing-from-html/59673>\
**Category:** Elasticsearch\
**Created:** [September 2, 2016, 2:18pm UTC](https://discuss.elastic.co/t/reindexing-from-html/59673 "2016-09-02T14:18:21Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![mbagatini](https://avatars.discourse-cdn.com/v4/letter/m/ec9cab/32.png) [@mbagatini](https://discuss.elastic.co/u/mbagatini)\
**Post date:** [September 2, 2016, 2:18pm UTC](https://discuss.elastic.co/t/reindexing-from-html/59673/1 "2016-09-02T14:18:21Z")

</div>

Hey folks,

I'm trying to make a simple reindex request from a HTML button, but keep getting a ElasticsearchParseException. Can someone give me a hand on this?

This is the HTML I'm using:

```
<html>
<head>
    <script type="text/javascript"
            src="http://www.google.com/jsapi"></script>
    <script type="text/javascript">
            $('#button1').click(function() {
                var tabWindowId = window.open('about:blank', '_blank'); 
                var form = tabWindowId.document.createElement("form");
                
                form.setAttribute("method", "POST");
                form.setAttribute("action", "http://localhost:9200/_reindex");
		       
		        var hiddenField = document.createElement("input");
            	hiddenField.setAttribute("type", "hidden");
              	hiddenField.setAttribute("name", "source");
                hiddenField.setAttribute("value", "\"source\":{\"index\":\"log-*\",\"query\":{\"term\":{\"requestId\":\"reallyniceanduniqueid123\"}}},\"dest\":{\"index\":\"log-permanentIndex\",\"version_type:external\"}");

		        form.appendChild(hiddenField);

                tabWindowId.document.body.appendChild(form);
                form.submit();
            });
    </script>
</head>
<body>
<form enctype="multipart/form-data">
  <input id="button1" type="button" value="Create Permalink" />
</form>
</body>
</html>

```

and this is the stack trace from elasticsearch:

> ElasticsearchParseException[Failed to derive xcontent]  
> at org.elasticsearch.common.xcontent.XContentFactory.xContent(XContentFactory.java:240)  
> at org.elasticsearch.index.reindex.RestReindexAction.handleRequest(RestReindexAction.java:67)  
> at org.elasticsearch.rest.BaseRestHandler.handleRequest(BaseRestHandler.java:54)  
> at org.elasticsearch.rest.RestController.executeHandler(RestController.java:205)  
> at org.elasticsearch.rest.RestController.dispatchRequest(RestController.java:166)  
> at org.elasticsearch.http.HttpServer.internalDispatchRequest(HttpServer.java:128)  
> at org.elasticsearch.http.HttpServer$Dispatcher.dispatchRequest(HttpServer.java:86)  
> at org.elasticsearch.http.netty.NettyHttpServerTransport.dispatchRequest(NettyHttpServerTransport.java:449)  
> at org.elasticsearch.http.netty.HttpRequestHandler.messageReceived(HttpRequestHandler.java:61)  
> at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70)  
> at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)  
> at org.jboss.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791)  
> at org.elasticsearch.http.netty.pipelining.HttpPipeliningHandler.messageReceived(HttpPipeliningHandler.java:60)  
> at org.jboss.netty.channel.SimpleChannelHandler.handleUpstream(SimpleChannelHandler.java:88)  
> at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)  
> at org.jboss.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791)  
> at org.jboss.netty.handler.codec.http.HttpChunkAggregator.messageReceived(HttpChunkAggregator.java:145)  
> at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70)  
> at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)  
> at org.jboss.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791)  
> at org.jboss.netty.handler.codec.http.HttpContentDecoder.messageReceived(HttpContentDecoder.java:108)  
> at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70)  
> at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)  
> at org.jboss.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791)

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [September 2, 2016, 2:32pm UTC](https://discuss.elastic.co/t/reindexing-from-html/59673/2 "2016-09-02T14:32:25Z")

</div>

Looks like unbalanced parenthesis but it is hard to tell.

I suggest dumping the request and having a look. Elasticearch doesn't support form encoded data and needs the body of the request to be a JSON object.

---

<div class="post-metadata">

**Author:** ![mbagatini](https://avatars.discourse-cdn.com/v4/letter/m/ec9cab/32.png) [@mbagatini](https://discuss.elastic.co/u/mbagatini)\
**Post date:** [September 2, 2016, 3:08pm UTC](https://discuss.elastic.co/t/reindexing-from-html/59673/3 "2016-09-02T15:08:32Z")

</div>

Is there a way to see that on Elasticsearch's log? I have set DEBUG level at logging.yml, but I can't see the request.

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [September 2, 2016, 3:22pm UTC](https://discuss.elastic.co/t/reindexing-from-html/59673/4 "2016-09-02T15:22:29Z")

</div>

The easiest way is to grab it from your browser's debug tools.

---

<div class="post-metadata">

**Author:** ![thiago](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thiago/32/32096_2.png) [@thiago](https://discuss.elastic.co/u/thiago)\
**Post date:** [September 3, 2016, 9:09am UTC](https://discuss.elastic.co/t/reindexing-from-html/59673/5 "2016-09-03T09:09:43Z")

</div>

Maybe because request body json is missing the initial "{"?

```
hiddenField.setAttribute("value", "\"source\":{\"index\":\"log-*\",\"query\":{\"term\":{\"requestId\":\"reallyniceanduniqueid123\"}}},\"dest\":{\"index\":\"log-permanentIndex\",\"version_type:external\"}");
```

---

<div class="post-metadata">

**Author:** ![mbagatini](https://avatars.discourse-cdn.com/v4/letter/m/ec9cab/32.png) [@mbagatini](https://discuss.elastic.co/u/mbagatini)\
**Post date:** [September 5, 2016, 8:33am UTC](https://discuss.elastic.co/t/reindexing-from-html/59673/6 "2016-09-05T08:33:44Z")

</div>

Tried that, does not work as well. I've also tried this:

var hiddenField = document.createElement("input");  
hiddenField.setAttribute("type", "hidden");  
hiddenField.setAttribute("name", "source");  
hiddenField.setAttribute("value", "{"source":{"index":"log-\*","query":{"term":{"requestId":"reallyniceanduniqueid123"}}}}");

var hiddenField2 = document.createElement("input");  
hiddenField2.setAttribute("type", "hidden");  
hiddenField2.setAttribute("name", "dest");  
hiddenField2.setAttribute("value", "{"dest":{"index":"log-permanentIndex","version\_type:external"}}");

and combinations with or without the "{" and using "JSON.stringify" and "form.setAttribute("enctype", "application/json")", no success so far.

---

<div class="post-metadata">

**Author:** ![thiago](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thiago/32/32096_2.png) [@thiago](https://discuss.elastic.co/u/thiago)\
**Post date:** [September 5, 2016, 2:33pm UTC](https://discuss.elastic.co/t/reindexing-from-html/59673/7 "2016-09-05T14:33:25Z")

</div>

Hello mbagatini,

Doing a quick research, it seems that browsers does not supports submitting forms with application/json encoding. So, instead of struggling to make it work, why don't you try submitting through ajax (i.e. jQuery's `$.ajax`). If you follow this path, remember to enable CORS in elasticsearch ([https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-http.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-http.html))

Cheers!

---

<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:22pm UTC](https://discuss.elastic.co/t/reindexing-from-html/59673/8 "2017-07-05T22:22:27Z")

</div>


