Elasticsearch javascript api

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

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

@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 ?

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

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