# Elasticsearch javascript api

**URL:** <https://discuss.elastic.co/t/elasticsearch-javascript-api/89357>\
**Category:** Elasticsearch\
**Created:** [June 14, 2017, 10:14am UTC](https://discuss.elastic.co/t/elasticsearch-javascript-api/89357 "2017-06-14T10:14:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jshraddha](https://avatars.discourse-cdn.com/v4/letter/j/e480ec/32.png) [@jshraddha](https://discuss.elastic.co/u/jshraddha)\
**Post date:** [June 14, 2017, 10:14am UTC](https://discuss.elastic.co/t/elasticsearch-javascript-api/89357/1 "2017-06-14T10:14:35Z")

</div>

Hi,

I am using elasticsearch javascript api for searching data. Forming a search query after getting the search word from the input text

```
    client.search({
                    index: 'my-index,
                    type: 'text-files',
                    body: {
                        query: {
                            match: {
                                "attachment.content": searchedWord
                            }
                        },
                        highlight : {
                            order : "score",
                            fields : {
                                "attachment.content" : {"fragment_size" : 1000}
                            }
                        }
                    }
                }).then(function (resp) {
                    var hits = resp.hits.hits;
                }, function (err) {
                    console.trace(err.message);
                });

```

Request is proper json is also not having any problem but when it hits through my javascript application I dont get any results. When I looked into network tab in browser I observed that request type is POST. Is there any api thrpugh which I can change request type to GET. Thing is above request works fine in my kibana console with GET request.  
Thanks in advance

---

<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:** [June 14, 2017, 11:27am UTC](https://discuss.elastic.co/t/elasticsearch-javascript-api/89357/2 "2017-06-14T11:27:48Z")

</div>

In Kibana the GET is actually translated to POST. Which is mandatory in a browser as it does not support GET with a body.

---

<div class="post-metadata">

**Author:** ![jshraddha](https://avatars.discourse-cdn.com/v4/letter/j/e480ec/32.png) [@jshraddha](https://discuss.elastic.co/u/jshraddha)\
**Post date:** [June 15, 2017, 6:58am UTC](https://discuss.elastic.co/t/elasticsearch-javascript-api/89357/3 "2017-06-15T06:58:07Z")

</div>

@dadoonet: Yes that worked. But I have experienced one more thing when I used javascript api to search data where the host is my ec2 instance the query is not getting formed as it was happening int he previous condition where I was querying to my localhost. When I give host as localhost it works properly with method post and request body but when I change host to my ec2 instance it is changing request method to "OPTIONS" and no request body is present in that request thought I have not changed anything except the host. Any idea why this happens ?

---

<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:** [June 15, 2017, 7:41am UTC](https://discuss.elastic.co/t/elasticsearch-javascript-api/89357/4 "2017-06-15T07:41:01Z")

</div>

No. I don't know. May be it asks first for some information at client startup before starting actual requests.

---

<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 13, 2017, 7:41am UTC](https://discuss.elastic.co/t/elasticsearch-javascript-api/89357/5 "2017-07-13T07:41:13Z")

</div>

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