同义词的几个关键点

2024-09-23 14:10:05 浏览数 (3)

同义词的几个关键点:

  1. 显示映射改为等同同义词。
  2. 同义词只用于搜索,使用synonym_graph,尽量少用于索引时间。
  3. 更新同义词的流程为关闭,更新,打开索引。
  4. 同义词最好以文件的形式存储在config目录,配置updateable=true,synonyms_path

代码语言:txt复制

GET my_synonyms/_settings
GET my_synonyms/_mapping

DELETE my_synonyms
PUT my_synonyms
{
  "settings": {
    "analysis": {
      "analyzer": {
        "my_synonyms_analyze": {
          "tokenizer": "standard",
          "filter": [
            "my_synonyms_filter"
          ]
        }
      },
      "filter": {
        "my_synonyms_filter": {
          "type": "synonym",
          "synonyms": [
            "elk,elkb,elasticsearch"
          ]
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "content": {
        "type": "text",
        "analyzer": "standard",
        "search_analyzer": "my_synonyms_analyze"
      }
    }
  }
}


POST my_synonyms/_close

PUT my_synonyms/_settings
{
  
  "analysis": {
    "filter": {
      "my_synonyms_filter": {
        "type": "synonym_graph",
        "synonyms": [
          "elk,elkb,elastic"
        ]
      }
    }
  }
}
POST my_synonyms/_open


POST my_synonyms/_doc/1
{
  "content":"elk is very powerful"
}

POST my_synonyms/_doc/2
{
  "content":"elkb is very powerful"
}

POST my_synonyms/_doc/3
{
  "content":"Elastic Stack is very powerful"
}


POST my_synonyms/_search
{
  "query": {
    "match": {
      "content": "elkb"
    }
  }
}





0 人点赞