# How do I construct complex queries to pass via rest

**URL:** <https://discuss.elastic.co/t/how-do-i-construct-complex-queries-to-pass-via-rest/106875>\
**Category:** Elasticsearch\
**Created:** [November 8, 2017, 1:51pm UTC](https://discuss.elastic.co/t/how-do-i-construct-complex-queries-to-pass-via-rest/106875 "2017-11-08T13:51:34Z")\
**Posts on this page:** 3\
**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 8, 2017, 1:51pm UTC](https://discuss.elastic.co/t/how-do-i-construct-complex-queries-to-pass-via-rest/106875/1 "2017-11-08T13:51:34Z")

</div>

HI All,

I'm using classic asp. Using the following simple example I am able to obtain data back to the asp application from elasticsearch:

```
Response.Buffer = true
	dim xml, toScreen 
	dim txt

	Set xml = Server.CreateObject("Microsoft.XMLHTTP")

	xml.Open "GET", "http://username:password@10.128.128.106:9200/myindex/_search?q='joe blogs',_source='path.real'", False
xml.Send

```

I now want to perform this type of query that I formulated directly in Kibana across rest. How do I create this as a search string for the above? :

```
  GET newsindex/_search
{
"query": {
"function_score": {
  "query": { "bool" : {"should": [ 
   { "term": { "headline": "brown" } },
   { "term": { "bodytext": "brown" } },
   { "term": { "headline": "fox" } },
   { "term": { "bodytext": "fox" } }
]}},
  "functions": [
    {
      "filter": {"match" : { "headline": "brown fox" }},
      "weight": 2
    },
    {
      "filter": {"match" : { "bodytext": "brown fox" }},
      "weight": 1
    },
    {
      "filter": {"match" : { "bodytext": "fox" }},
      "weight": 3
    },
    {
      "filter": {"match" : { "bodytext": "brown" }},
      "weight": 3
    },
    {
      "filter": {"match" : { "headline": "brown" }},
      "weight": 4
    },
    {
      "filter": {"match" : { "headline": "fox" }},
      "weight": 4
    }
    ],
  "score_mode": "sum"
}
},"sort": [
{
  "_score": {
    "order": "asc"
  }
}
], 
"_source":["headline", "bodytext"]
}
```

---

<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 9, 2017, 9:52am UTC](https://discuss.elastic.co/t/how-do-i-construct-complex-queries-to-pass-via-rest/106875/2 "2017-11-09T09:52:03Z")

</div>

I've managed to figure it out.

---

<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 7, 2017, 9:52am UTC](https://discuss.elastic.co/t/how-do-i-construct-complex-queries-to-pass-via-rest/106875/3 "2017-12-07T09:52:13Z")

</div>

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