简体   繁体   中英

index field with not_analyzed in elastic search java

I am indexing city names (eg "New York") in elasticsearch which obviously cannot be white space tokenized. How do I index terms using java api?

Currently I have code as below..

 bulkRequest.add(client.prepareIndex("myIndex", "collection", if)
                .setSource(mapper.writeValueAsString(entity)));


    BulkResponse bulkResponse = bulkRequest.execute().actionGet();

Please explain what you want exactly. we need to specify the analyzers while we create mapping.

An analyzer is a combination of a tokenizer and one or more text filters. The tokenizer is responsible for breaking apart the text into individual “tokens”, which could be words or pieces of words. The filters are responsible for transforming and removing tokens from the indexed content

eg making all text lowercase, removing common words, indexing synonyms, etc.

Analyzer of the field will decide the tokenize. please check the analyzer for the city name field.

please have a look on Keyword analyzer.

Analyzer can be seen in the mapping file. while create the index you need to set the analyzer else the default analyzer will be applied while index the field (dynamic mapping).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM