2
votes

I am using elasticsearch in my project in Java, with the document format like

/index/type/_mapping 
{
  "my_id" : "string"
}

Now, suppose the my_id values are A01, A02, A01.A1, A012.AB0

For the query,

{
 "query" : {
   "term" : { 
    "my_id" : "a01"
    }
  }
}

Observed : the documents returned are for A01, A01.A1, A012.AB0

Expected : I need the A01 document only.

I looked for the solution and found that i would have to use a custom analyzer for my_id field. I do not want to change my mapping for the document. Also, I used "index": "not_analyzed" in the query but there was no change in the output.

1
Are you sure you included all relevant information in this question? I entered pretty much exactly what you provided in this play, and the results are what you expected.Njal Karevoll
I seem to have found the reason why my fetched documents were wrong. The ,for A01 query i got documents for A01, A01.01, A01.A01 etc and when I replaced the '.' of my_id with '_', I got only A01. This worked for me.Yogesh Patil
I think the '.' worked as a wildcard to match anything that comes later. Didn't find anything on it though.Yogesh Patil

1 Answers

0
votes

Yes, you could use 'not_analyzed' analyzer, but try to use term filter instead of term query Also check current mapping of the document