Searching year, month, and date split into different fields

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

Wrapper your boolean clauses in a boolean filter:

--
Ivan

On Wed, Aug 1, 2012 at 10:11 AM, curious 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

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