# Searching year, month, and date split into different fields

**URL:** <https://discuss.elastic.co/t/searching-year-month-and-date-split-into-different-fields/8599>\
**Category:** Elasticsearch\
**Created:** [August 1, 2012, 5:11pm UTC](https://discuss.elastic.co/t/searching-year-month-and-date-split-into-different-fields/8599 "2012-08-01T17:11:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![curious](https://avatars.discourse-cdn.com/v4/letter/c/6bbea6/32.png) [@curious](https://discuss.elastic.co/u/curious)\
**Post date:** [August 1, 2012, 5:11pm UTC](https://discuss.elastic.co/t/searching-year-month-and-date-split-into-different-fields/8599/1 "2012-08-01T17:11:09Z")

</div>

I have year, month, and date split into different fields. To search  
documents for specific dates (I have to retrieve in 7-day batches), I am  
trying to use multiple "AND" clauses in a filter.

1. The problem is that the query works fine with two "and" clauses, but as  
soon as I add the third - it stops working and says: nested:  
QueryParsingException[[mjm] [filtered] query does not support [and]];

"query" : {

```
 "filtered" : {

    "query" : {

        "match_all" : {}

    },

    "filter" : {

```

"and" : [

{"term" : { "date.year" : "2011" }},

{"term" : { "date.month" : "5" }},

{"term" : { "date.date" : "1" }}

],

"and" : [

{"term" : { "date.year" : "2011" }},

{"term" : { "date.month" : "5" }},

{"term" : { "date.date" : "2" }}

],

"and" : [

{"term" : { "date.year" : "2011" }},

{"term" : { "date.month" : "5" }},

{"term" : { "date.date" : "3" }}

]

```
    }

}

```

}

1. Is there a more efficient method to do the above search?

Thanks

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [August 1, 2012, 5:14pm UTC](https://discuss.elastic.co/t/searching-year-month-and-date-split-into-different-fields/8599/2 "2012-08-01T17:14:50Z")

</div>

Wrapper your boolean clauses in a boolean filter:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

--  
Ivan

On Wed, Aug 1, 2012 at 10:11 AM, curious [springdalian@gmail.com](mailto:springdalian@gmail.com) wrote:

> I have year, month, and date split into different fields. To search  
> documents for specific dates (I have to retrieve in 7-day batches), I am  
> trying to use multiple "AND" clauses in a filter.
> 
> 1. The problem is that the query works fine with two "and" clauses, but as  
> soon as I add the third - it stops working and says: nested:  
> QueryParsingException[[mjm] [filtered] query does not support [and]];
> 
> "query" : {
> 
> ```
> "filtered" : {
> 
> "query" : {
> 
> "match_all" : {}
> 
> },
> 
> "filter" : {
> 
> ```
> 
> "and" : [
> 
> {"term" : { "date.year" : "2011" }},
> 
> {"term" : { "date.month" : "5" }},
> 
> {"term" : { "date.date" : "1" }}
> 
> ],
> 
> "and" : [
> 
> {"term" : { "date.year" : "2011" }},
> 
> {"term" : { "date.month" : "5" }},
> 
> {"term" : { "date.date" : "2" }}
> 
> ],
> 
> "and" : [
> 
> {"term" : { "date.year" : "2011" }},
> 
> {"term" : { "date.month" : "5" }},
> 
> {"term" : { "date.date" : "3" }}
> 
> ]
> 
> ```
> }
> 
> }
> 
> ```
> 
> }
> 
> 1. Is there a more efficient method to do the above search?
> 
> Thanks

---

<div class="post-metadata">

**Author:** ![curious](https://avatars.discourse-cdn.com/v4/letter/c/6bbea6/32.png) [@curious](https://discuss.elastic.co/u/curious)\
**Post date:** [August 1, 2012, 8:55pm UTC](https://discuss.elastic.co/t/searching-year-month-and-date-split-into-different-fields/8599/3 "2012-08-01T20:55:28Z")

</div>

Thanks for the direction Ivan. The following is working (used dismax to  
return results of the individual bool queries):

"query" : {  
"dis\_max" : {  
"queries" : [  
{

"bool" : {

```
  "must" : [

```

{"term" : { "date.year" : "2011" }},

{"term" : { "date.month" : "5" }},

{"term" : { "date.date" : "1" }}

```
 ]

```

}

```
        },
        {

```

"bool" : {

```
  "must" : [

```

{"term" : { "date.year" : "2011" }},

{"term" : { "date.month" : "5" }},

{"term" : { "date.date" : "2" }}

```
 ]

```

}

```
        }
    ]
  }

```

}

On Wednesday, August 1, 2012 1:11:09 PM UTC-4, curious wrote:

> I have year, month, and date split into different fields. To search  
> documents for specific dates (I have to retrieve in 7-day batches), I am  
> trying to use multiple "AND" clauses in a filter.
> 
> 1. The problem is that the query works fine with two "and" clauses, but as  
> soon as I add the third - it stops working and says: nested:  
> QueryParsingException[[mjm] [filtered] query does not support [and]];
> 
> "query" : {
> 
> ```
> "filtered" : {
> 
> "query" : {
> 
> "match_all" : {}
> 
> },
> 
> "filter" : {
> 
> ```
> 
> "and" : [
> 
> {"term" : { "date.year" : "2011" }},
> 
> {"term" : { "date.month" : "5" }},
> 
> {"term" : { "date.date" : "1" }}
> 
> ],
> 
> "and" : [
> 
> {"term" : { "date.year" : "2011" }},
> 
> {"term" : { "date.month" : "5" }},
> 
> {"term" : { "date.date" : "2" }}
> 
> ],
> 
> "and" : [
> 
> {"term" : { "date.year" : "2011" }},
> 
> {"term" : { "date.month" : "5" }},
> 
> {"term" : { "date.date" : "3" }}
> 
> ]
> 
> ```
> }
> 
> }
> 
> ```
> 
> }
> 
> 1. Is there a more efficient method to do the above search?
> 
> Thanks

---

<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:** [July 6, 2017, 3:18am UTC](https://discuss.elastic.co/t/searching-year-month-and-date-split-into-different-fields/8599/4 "2017-07-06T03:18:06Z")

</div>


