Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to add IK thesaurus in Elasticsearch

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to add IK thesaurus in Elasticsearch". The content in the article is simple and clear, easy to learn and understand. Please follow the editor's train of thought to study and learn "how to add IK thesaurus in Elasticsearch".

First configure the following configuration under the config directory of Elasticsearch

$: vi elasticsearch/config/elasticsearch.yml

Add the following configuration at the bottom:

# add the following code at the bottom

Index:

Analysis:

Analyzer:

Ik_syno:

Type: custom

Tokenizer: ik_max_word

Filter: [my_synonym_filter]

Ik_syno_smart:

Type: custom

Tokenizer: ik_smart

Filter: [my_synonym_filter]

Filter:

My_synonym_filter:

Type: synonym

Synonyms_path: ik/config/synonym.txt

Add IK thesaurus

There is a line of ik/config/synonym.txt configured above, so we create the directory ik/config/ under the elasticsearch.yml sibling directory, and then create the file synonym.txt.

Then edit synonym.txt and enter our synonym.

[elasticsearch@admin config] $vi ik/config/synonym.txt

Es,search,elasticsearch

Script, js,javascript

Separate with English commas, a synonym for behavior.

Restart Elasticsearch after saving, and then create a Mapping.

3. Java API creates Mapping

Need to specify our index word splitter, and search word splitter.

Here is the main code.

.startObject ("title")

Field ("type", "string")

Field ("store", "yes")

/ / specify index analyzer as ik_syno

Field ("analyzer", "ik")

/ / specify search_analyzer as ik_syno

Field ("searchAnalyzer", "ik_syno")

.endObject ()

Thank you for your reading, the above is the content of "how to add IK thesaurus in Elasticsearch". After the study of this article, I believe you have a deeper understanding of how to add IK thesaurus in Elasticsearch, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report