Searching year, month, and date split into different fields


(curious) #1

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


(Ivan Brusic) #2

Wrapper your boolean clauses in a boolean filter:
http://www.elasticsearch.org/guide/reference/query-dsl/bool-filter.html

--
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


(curious) #3

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


(system) #4