5

I want to to query in the dats while using the querystring.

From what I can read here this should work.

{
    "query": {
        "query_string": {
            "query": "date:[20100101 TO 20141231]"

        }
    },
    "size": 10

}

I get no errors but no results either.

I have date fields in the mapping (shortened for your convenience).

{
   "cases": {
      "mappings": {
         "texcaseelastic": {
            "properties": {
               "dateIn": {
                  "type": "date",
                  "format": "dateOptionalTime"
               },
               "type": {
                  "type": "string"
               }
            }
         }
      }
   }
}

And I have at least a few that should fall in that range.

"dateIn": "2011-11-21T00:00:00",

Any help would be welcome. Thanks.

6
  • 1
    Is that a typo in your query, that your field name is date instead of dateIn? Commented May 15, 2014 at 16:08
  • No, that is how I understand it to work, I thought date meant all fields with a date in them. But you are saying that that should be my fieldname datin? Commented May 15, 2014 at 18:10
  • Yes. Should be field name. Commented May 15, 2014 at 18:11
  • darn, stupid me. Can you make that an answer so I can accept it? Commented May 15, 2014 at 18:13
  • can I do a search on all date fields for a date with the querystring Commented May 15, 2014 at 18:16

2 Answers 2

6

There is a typo in your query. You are doing a search by specific field and your field name is incorrect.

Change date to dateIn, like the following:

{
    "query": {
        "query_string": {
            "query": "dateIn:[20100101 TO 20141231]"

        }
    },
    "size": 10

}
Sign up to request clarification or add additional context in comments.

Comments

0
{
    "query":{"range": {"date_column_name": {"gte": "2011-11-20T00:00:00", "lte": "2011-11-22T00:00:00"}}},
    "size": 10
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.