# Searching upon two date fields within a main filter

**URL:** <https://discuss.elastic.co/t/searching-upon-two-date-fields-within-a-main-filter/160099>\
**Category:** Elasticsearch\
**Created:** [December 10, 2018, 5:41am UTC](https://discuss.elastic.co/t/searching-upon-two-date-fields-within-a-main-filter/160099 "2018-12-10T05:41:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rpm1984](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rpm1984/32/36595_2.png) [@rpm1984](https://discuss.elastic.co/u/rpm1984)\
**Post date:** [December 10, 2018, 5:41am UTC](https://discuss.elastic.co/t/searching-upon-two-date-fields-within-a-main-filter/160099/1 "2018-12-10T05:41:21Z")

</div>

I have a document like this:

```auto
{
  "listings": {
    "mappings": {
      "listing": {
        "properties": {
          "auctionOn": {
            "type": "date"
          },
          "inspections": {
            "type": "nested",
            "properties": {
              "endsOn": {
                "type": "date"
              },
              "startsOn": {
                "type": "date"
              }
            }
          },
        // more fields.. snipped for brevity
        }
      }
    }
  }
}

```

and i would like to perform the following search: (needs to be a bool filter.. no scoring req'd)

- return documents any of the `inspections.startsOn` matches any of the dates provided (_if_ they are provided)  
OR
- return documents where `auctionOn` matches the date provided (_if_ it's provided)

they can also specify to search for a) inspections only, b) auctions only. if not provided, either of the dates need to match.

So in other words, possible searches:

- Search where there are any inspections/auctions
- Search where there are any inspections
- Search where there are any auctions
- Search where there are any inspections/auctions on the dates provided
- Search where there are any inspections on the dates provided
- Search where there are any auctions on the dates provided

Now, i'm already in a `bool` query filter:

```auto
{
   "query":
   {
      "bool":
      {
          "filter":[{"terms":{"location.suburb":["Camden"]}}
      }
   }
}

```

and i need this new filter to be seperate. so.. this is like a _nested_ or filter, within a main bool filter?

So if provided "Suburb = Camden, Dates = ['2018-11-01','2018-11-02']'

then it should return documents where the suburb = Camden _and_ either the inspections or auction date includes one of the dates provided.

I'm kinda stumped on how to do it, so any help would be much appreciated!

---

<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:** [January 7, 2019, 5:41am UTC](https://discuss.elastic.co/t/searching-upon-two-date-fields-within-a-main-filter/160099/2 "2019-01-07T05:41:24Z")

</div>

Closed on January 7, 2019, 5:41am UTC

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