I have a few elasticsearch fields that I don\'t want to analyze before indexing. I have read that the right way to do this is by altering the index mapping. Right now my map
So, turns out elasticsearch docs are way outdated on that topic. not_analyzed does not exist anymore and string is now text. After some trial and error I came up with this:
CreateIndexRequest createIndexRequest = new CreateIndexRequest("yourIndexName");
XContentBuilder mapping = jsonBuilder()
.startObject()
.startObject("properties")
.startObject("yourProperty")
.field("type", "keyword")
.endObject()
.endObject()
.endObject();
createIndexRequest.mapping("yourEntityName", mapping);
client.indices().create(createIndexRequest);
Now yourProperty can be queried for exact value only with term query.