# Sending query via classic asp works one way but not another

**URL:** <https://discuss.elastic.co/t/sending-query-via-classic-asp-works-one-way-but-not-another/107205>\
**Category:** Elasticsearch\
**Created:** [November 10, 2017, 3:11pm UTC](https://discuss.elastic.co/t/sending-query-via-classic-asp-works-one-way-but-not-another/107205 "2017-11-10T15:11:21Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![bilpor](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bilpor/32/24043_2.png) [@bilpor](https://discuss.elastic.co/u/bilpor)\
**Post date:** [November 10, 2017, 3:11pm UTC](https://discuss.elastic.co/t/sending-query-via-classic-asp-works-one-way-but-not-another/107205/1 "2017-11-10T15:11:21Z")

</div>

HI All,

If I send a simple query to Elastic using the following code construct, in the response back I obtain my expected results:

```
webaddress = "http://localhost:9200/" + index + "/_search?q='hello world'"

set xml = server.Createobject("MSXML2.ServerXMLHTTP")

	xml.Open "GET", webaddress ,False

	xml.setRequestHeader "Authorization", "Basic " & Base64Encode("elastic:elastic123")

	xml.Send

```

Now if I want to send a much more complex query such that It's not practical or possibly even possible to place the query on a single 'q' parameter as above. i.e.

the query:

```
get myindex/_search
{
    "query":{"match": {"headline": "overseas territory"},
             "match" : {"bodytext": "british territory"}
            }
}

```

So I would build this up into a variable. lets call it mySearch

Then my webaddress becomes :

`webaddress = "http://localhost:9200/" + index + "/_search"`

and xml.send becomes :

`xml.Send mySearch`

mySearch gets ignored and I receive back a default first 10 records from the variable webaddress.

How should I pass my complex search so that it is recognised. I dont have the luxury of curl

---

<div class="post-metadata">

**Author:** ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)\
**Post date:** [November 13, 2017, 1:17am UTC](https://discuss.elastic.co/t/sending-query-via-classic-asp-works-one-way-but-not-another/107205/2 "2017-11-13T01:17:11Z")

</div>

You will need to use `"POST"` in order to be able to send a JSON body to the `_search` endpoint; as far as I am aware, `MSXML2.ServerXMLHTTP` cannot send a request body with `"GET"`. I'd also recommend setting

```auto
xml.setRequestHeader "Content-Type", "application/json"

```

If you need to interact with Elasticsearch from Classic ASP more than this, you might be able to save yourself some considerable time by creating a [COM Callable Wrapper](https://docs.microsoft.com/en-us/dotnet/framework/interop/com-callable-wrapper) and using COM interop with [the .NET client to interact with Elasticsearch.](https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/index.html)

---

<div class="post-metadata">

**Author:** ![bilpor](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bilpor/32/24043_2.png) [@bilpor](https://discuss.elastic.co/u/bilpor)\
**Post date:** [November 13, 2017, 10:52am UTC](https://discuss.elastic.co/t/sending-query-via-classic-asp-works-one-way-but-not-another/107205/3 "2017-11-13T10:52:44Z")

</div>

HI changing to POST and also changing my index such that all the properties were declared as lowercase has given me better results, however on return, my response object only has the first 10 records being returned. When I'm expecting more. Via Kibana the 10 returned match the first 10 in the Kibana results window.

---

<div class="post-metadata">

**Author:** ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)\
**Post date:** [November 14, 2017, 11:25pm UTC](https://discuss.elastic.co/t/sending-query-via-classic-asp-works-one-way-but-not-another/107205/4 "2017-11-14T23:25:20Z")

</div>

A search request will return only the top 10 scored documents by default. If you want to return more then you can [use `"size"` on the request, and use it in conjunction with `"from"` for pagination.](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-from-size.html)

Bear in mind that this is not an efficient way to deeply paginate a _large_ dataset; for this, you may consider using the [scroll API](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html) or [search after API.](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-search-after.html)

---

<div class="post-metadata">

**Author:** ![bilpor](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bilpor/32/24043_2.png) [@bilpor](https://discuss.elastic.co/u/bilpor)\
**Post date:** [November 15, 2017, 11:40am UTC](https://discuss.elastic.co/t/sending-query-via-classic-asp-works-one-way-but-not-another/107205/5 "2017-11-15T11:40:46Z")

</div>

I have had some success using the scroll API. However the issue I now have is that there is nothing being returned that I can test when all data has been returned. I thought I could check the `txt.hits.hits.length` Property, but on the last page in the Kibana output window it shows as `[]` but back in classic asp it just says `'Empty'` but it's not in an 'Empty' state that classic asp would recognise and it doesn't return the literal word 'Empty'. Calling the scoll API continues to send back a valid scroll\_id, took still continues to have a number greater than 0, even though nothing is returned, I've basically got nothing to interpret to tell me when I've reached the end.

---

<div class="post-metadata">

**Author:** ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)\
**Post date:** [November 15, 2017, 12:02pm UTC](https://discuss.elastic.co/t/sending-query-via-classic-asp-works-one-way-but-not-another/107205/6 "2017-11-15T12:02:33Z")

</div>

> However the issue I now have is that there is nothing being returned that I can test when all data has been returned.

When no more documents are being returned, you've reached the end. You can calculate how many calls this will be ahead of time from the first call, by using the `total` in the response of the first response in conjunction with the `size` parameter that's used.

---

<div class="post-metadata">

**Author:** ![bilpor](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bilpor/32/24043_2.png) [@bilpor](https://discuss.elastic.co/u/bilpor)\
**Post date:** [November 15, 2017, 3:35pm UTC](https://discuss.elastic.co/t/sending-query-via-classic-asp-works-one-way-but-not-another/107205/7 "2017-11-15T15:35:05Z")

</div>

Ok, thank you....This seems to work directly via Kibana doing the Math. So I'll fo and try my Classic asp now, though it makes my script a bit more messy :).

---

<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:** [December 13, 2017, 3:35pm UTC](https://discuss.elastic.co/t/sending-query-via-classic-asp-works-one-way-but-not-another/107205/8 "2017-12-13T15:35:28Z")

</div>

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