How Can I convert raw query with “aggs” to Nest query?

I have this raw query that is being used in Kibana to get and show some data from ElasticSearch.
{
"query": {
"bool": {
"must": [
{
"query_string": {
"query": "",
"analyze_wildcard": true
}
},
{
"match": {
"type": {
"query": "Error",
"type": "phrase"
}
}
},
{
"match": {
"area": {
"query": "usa",
"type": "phrase"
}
}
},
{
"query_string": {
"analyze_wildcard": true,
"query": "
"
}
},
{
"range": {
"requestTimestamp": {
"gte": 1509369446307,
"lte": 1509383846307,
"format": "epoch_millis"
}
}
}
],
"must_not": []
}
},
"size": 0,
"_source": {
"excludes": []
},
"aggs": {
"2": {
"date_histogram": {
"field": "requestTimestamp",
"interval": "5m",
"time_zone": "America/Los_Angeles",
"min_doc_count": 1
},
"aggs": {
"4": {
"filters": {
"filters": {
"Readable Title 1": {
"query_string": {
"query": "FirstField:("MyMachine-Prod-") AND SecondField:("Message1")",
"analyze_wildcard": true
}
},
"Readable Title 2": {
"query_string": {
"query": "FirstField:("MyMachine-Prod-
") AND SecondField:("Message2")",
"analyze_wildcard": true
}
},
"Readable Title 3": {
"query_string": {
"query": "FirstField:("MyMachine-Prod-") AND SecondField:("Message3")",
"analyze_wildcard": true
}
},
"Readable Title 4": {
"query_string": {
"query": "SecondField:("Message4;") AND FirstField:("MyMachine-Prod-
")",
"analyze_wildcard": true
}
},
"Readable Title 5": {
"query_string": {
"query": "SecondField:("Message5") AND FirstField:("MyMachine-Prod-")",
"analyze_wildcard": true
}
},
"Readable Title 6": {
"query_string": {
"query": "SecondField:("Message6") AND FirstField:("MyMachine-Prod-
")",
"analyze_wildcard": true
}
},
"Readable Title 7": {
"query_string": {
"query": "SecondField:("Message7") AND FirstField:("MyMachine-Prod-")",
"analyze_wildcard": true
}
},
"Readable Title 8": {
"query_string": {
"query": "SecondField:("Message8") AND FirstField:("MyMachine-Prod-
")",
"analyze_wildcard": true
}
},
"Readable Title 9": {
"query_string": {
"query": "FirstField:("MyMachine-Prod-") AND SecondField:("Message9")",
"analyze_wildcard": true
}
},
"Readable Title 10": {
"query_string": {
"query": "FirstField:("MyMachine-Prod-
") AND SecondField:("Message10")",
"analyze_wildcard": true
}
},
"Readable Title 11": {
"query_string": {
"query": "FirstField:("MyMachine-Prod-") AND SecondField:("Message11")",
"analyze_wildcard": true
}
}
}
},
"aggs": {
"1": {
"cardinality": {
"field": "Guid"
}
}
}
}
}
}
},
"highlight": {
"pre_tags": [
"@kibana-highlighted-field@"
],
"post_tags": [
"@/kibana-highlighted-field@"
],
"fields": {
"
": {
"highlight_query": {
"bool": {
"must": [
{
"query_string": {
"query": "",
"analyze_wildcard": true,
"all_fields": true
}
},
{
"match": {
"type": {
"query": "Error",
"type": "phrase"
}
}
},
{
"match": {
"area": {
"query": "usa",
"type": "phrase"
}
}
},
{
"query_string": {
"analyze_wildcard": true,
"query": "
",
"all_fields": true
}
},
{
"range": {
"requestTimestamp": {
"gte": 1509369446307,
"lte": 1509383846307,
"format": "epoch_millis"
}
}
}
],
"must_not": []
}
}
}
},
"fragment_size": 2147483647
}
}

I need to get convert this query to Nest query and run it from inside C# console application to get the same data in my application, then I will do some processing on the returned data. Can anyone please help me in converting this query to Nest query?

Note: I have class in my C# code that matches has all the fields that are in my ElasticSearch Index and I'm able to do simple queries on it.

What have you tried so far?

If you'd just like to run the query using a JSON string, you can do so using the low level client. If you use the low level client exposed on the high level client, you can also get back a strongly typed search response

var client = new ElasticClient();

// substitute for your JSON string
var query = @"
{
  ""query"": {
    ""match"": {
      ""_all"": {
        ""query"": ""some query""
      }
    }
  }
}";

var searchResult = client.LowLevel.Search<SearchResponse<MyDocument>>(query);

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