How to configure elasticsearch synonyms
Editor to share with you how to configure elasticsearch synonyms, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Under the config directory, store synonyms.txt
Curl-XPOST 'http://localhost:9200/sy'-d' {
"analysis": {
"analyzer": {
"mysynonym": {
"type": "custom"
"tokenizer": "ik_max_word"
"filter": [
"local_synonym"
]
}
}
"filter": {
"local_synonym": {
"expand": true
"ignore_case": true
"type": "synonym"
"synonyms_path": "synonym.txt"
}
}
}
}'
Curl-XPOST 'http://localhost:9200/sy/sy/_mapping'-d' {
"sy": {
"_ all": {
"search_analyzer": "ik_smart"
"analyzer": "mysynonym"
}
"properties": {
"name": {
"type": "string"
}
"title": {
"type": "string"
}
"number": {
"type": "long"
}
}
}
}
}'
Curl-XPOST http://127.0.0.1:9200/sy/sy/1?pretty-d'
{"name": "Tomato", "title": "FQtitle", "number": 10000}
'
Curl-XPOST http://127.0.0.1:9200/sy/sy/2?pretty-d'
{"name": "Tomato", "title": "XHStitle", "number": 20000}
'
Curl-XPOST http://127.0.0.1:9200/sy/sy/3?pretty-d'
{"name": "Virgin fruit", "title": "SVGtitle", "number": 30000}
'
Curl-XGET 'http://127.0.0.1:9200/sy/sy/_search?pretty'-d' {
"from": 0
"size": 2
"query": {
"bool": {
"must": {
"query_string": {
"query": "Virgin fruits"
}
}
}
}
}'
The above is all the content of the article "how to configure elasticsearch synonyms". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!