Configure elasticsearch mapping with java api

后端 未结 4 1408
说谎
说谎 2020-12-10 13:56

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

4条回答
  •  佛祖请我去吃肉
    2020-12-10 14:34

    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.

提交回复
热议问题