Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to add IK thesaurus in Elasticsearch

Shulou Source: shulou.com Published: 2022-06-01 12:45:46 10月04日 Update

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!

Tags: Synonyms thesaurus configuration directory learning line code content synonyms face level that is ideas situations files articles more knowledge knowledge points articles Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB OPPO Reno Apple vpn Docker