0

I am trying to search for an exact match of the date field on the elastic search index, but elastic index returns data that doesn't match search criteria or even when the date field is null.

sorry for providing screenshots for the JSON code. somehow stackoverflow is not letting me to post the question, even when I tried to format the code with ctrl+k, I tried with other tags also without success.

here is the short version of the index.

elastic index

when I try to search the index using the below query,

search with name and date of birth

elastic is returning data where the name is matching with Tom but the birth date not matching, some results match date of birth, and some results have a birth date of 1998-04-12 where the year or month or day is not matching in the given input query or even returning birth date with null values.

I tried replacing the date query from match to term but got the same result. I tried to replace the date query with a range query (as I know internally elastic search converts date queries to range queries, but I still wanted to try), but I still had the same issue.

is there anything I can do which returns the proper results?

I tried searching on the date field alone by removing the name.

search with just date of birth

even above one resulting in the same issue.

here is the version of elastic I am using.

elastic version

is this a known issue or is something I am doing wrong? any help would be appreciated.

P.S, the elastic index schema I provided is a small version of what I am using. other date fields also have the same issue.

I have tried with match, term, and range queries and provided date format also in queries without success.

5
  • I would recommend to check it with Rest API client. Personally I don't usually use dev.console , I simply make Java Rest API. It has more information on error message part , if the query doesn't generate expected outcome. Commented Jun 12, 2023 at 1:43
  • do you mean elastic sdk? what i am using is already rest api with json payload as request. Commented Jun 12, 2023 at 2:07
  • Currently as far as I see you are working on Kibana interface in the Dev Console. What I mean is, you can write Rest API (comfortable language) and see stack trace more vividly Commented Jun 12, 2023 at 3:08
  • I am not using Kibana, i am using Rest interface and it will not provide any additional info, either data or empty or exception if the query is wrong Commented Jun 12, 2023 at 12:40
  • i found the issue, its nothing to do with elastic query. the way i was understanding the output from elastic is wrong. The name is array, some records in array have date of birth matching the one which I specified in query and other objects in the array have null or different dob. But elastic is return the complete array. In below example data I am getting the array, even DOB is matching in only 1 object in the array [ { “Dob” : null }, { “Dob”: “1950-05-05” } ] Commented Jun 12, 2023 at 15:22

1 Answer 1

0

When querying dates types you should use a format property on your query, much like how you specified it on your index template.

https://www.elastic.co/guide/en/elasticsearch/reference/current/date.html#multiple-date-formats

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

1 Comment

as posted in question, i did with format also, if i remember properly i was not able to give format when doing term or match query, but i was when i tried range query and results are same. { "gte" : "2014-09-17", "lte" :"2014-09-17", "format" :"yyyy-MM-dd" }

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.