# Using logical AND query in Kibana

**URL:** <https://discuss.elastic.co/t/using-logical-and-query-in-kibana/229276>\
**Category:** Elasticsearch\
**Created:** [April 22, 2020, 1:53pm UTC](https://discuss.elastic.co/t/using-logical-and-query-in-kibana/229276 "2020-04-22T13:53:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![adiksl](https://avatars.discourse-cdn.com/v4/letter/a/f14d63/32.png) [@adiksl](https://discuss.elastic.co/u/adiksl)\
**Post date:** [April 22, 2020, 1:53pm UTC](https://discuss.elastic.co/t/using-logical-and-query-in-kibana/229276/1 "2020-04-22T13:53:41Z")

</div>

I am trying to implement a simple query in Kibana and then in C# NEST. I am from a SQL background and am struggling to find documentation to perform a relatively simple SQL query in Elasticsearch. The query I am trying to implement is effectively......

```auto
SELECT * FROM table 
WHERE logdate > STR_TO_DATE('2020-02-01 23:59:59','%Y-%m-%d %H:%i:%s')
AND logdate < STR_TO_DATE('2020-02-03 00:00:00','%Y-%m-%d %H:%i:%s')
AND username = 'user01'

```

I can do them as individual kibana queries....

```auto
GET table/_search
{
  "query": {
    "range": {
      "logdate": {
        "gt": "2020-02-01T23:59:59",
        "lt": "2020-02-03T00:00:00"
      }
    }
  }
}

GET table/_search
{
  "query": {
    "match": {
      "username": "user01"
    }
  }
}

```

But when I try and combine them into one query I get a "parsing\_exception" error...

```auto
GET table/_search
{
  "query" : {
    "bool" : {
      "must": [
        {
          "match": {
            "username": "user01"
          },
          "range": {
            "logdate": {
              "gt": "2020-02-01T23:59:59",
              "lt": "2020-02-03T00:00:00"
            }
          }
        }
      ]
    }
  }
}

```

I have looked at the Elasticsearch documentation and can't seem to find the answer so any help would be appreciated, thanks in advance

---

<div class="post-metadata">

**Author:** ![Andrei\_Stefan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrei_stefan/32/47533_2.png) [@Andrei\_Stefan](https://discuss.elastic.co/u/Andrei_Stefan)\
**Post date:** [April 23, 2020, 7:08am UTC](https://discuss.elastic.co/t/using-logical-and-query-in-kibana/229276/2 "2020-04-23T07:08:19Z")

</div>

Try this one:

```auto
{
  "query" : {
    "bool" : {
      "must": [
         {
          "match": {
            "username": "user01"
          }
         },
         {
           "range": {
            "logdate": {
              "gt": "2020-02-01T23:59:59",
              "lt": "2020-02-03T00:00:00"
            }
          }
        }
      ]
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![adiksl](https://avatars.discourse-cdn.com/v4/letter/a/f14d63/32.png) [@adiksl](https://discuss.elastic.co/u/adiksl)\
**Post date:** [April 23, 2020, 8:29am UTC](https://discuss.elastic.co/t/using-logical-and-query-in-kibana/229276/3 "2020-04-23T08:29:40Z")

</div>

Excellent works a treat, thanks you for your help. Now to try and get it working with NEST.

---

<div class="post-metadata">

**Author:** ![adiksl](https://avatars.discourse-cdn.com/v4/letter/a/f14d63/32.png) [@adiksl](https://discuss.elastic.co/u/adiksl)\
**Post date:** [April 23, 2020, 3:24pm UTC](https://discuss.elastic.co/t/using-logical-and-query-in-kibana/229276/4 "2020-04-23T15:24:03Z")

</div>

Have tried converting to NEST but have errors as string to double conversion on dates, then cannot convert lambda expressions to types 'Nest.ISearchRequest'  
& 'Nest.QueryContainer

```auto
Client.SearchAsync<AuditRecord>(s => s
.From(0)
.Take(10)
.Query(q => q
.Bool(b => b
.Must(m => m
.Range(r => r
.Field("Timestamp")
.GreaterThan("2017-03-07T13:30:00")
.LessThan("2017-03-07T13:40:00")
)
)
.MatchPhrase(mp => mp   
.Field("Action")
.Query("Week No: 30")
)                                    
)
)).Result.Documents.ToList();

```

---

<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:** [May 21, 2020, 3:24pm UTC](https://discuss.elastic.co/t/using-logical-and-query-in-kibana/229276/5 "2020-05-21T15:24:32Z")

</div>

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