ElasticSearch中单索引多同义词路径的实现

crcmnpdw  于 2022-12-03  发布在  ElasticSearch
关注(0)|答案(1)|浏览(187)

我试图在ElasticSearch中为单个索引实现多个synonym_path

"settings": {
"index": {
  "analysis": {
    "analyzer": {
      "synonym": {
        "tokenizer": "whitespace",
        "filter": ["synonym"]
      }
    },
    "filter": {
      "bool": {
          "should": [{
            "synonym": {
              "type": "synonym",
              "synonyms_path": "synonyms.txt",
              "ignore_case": true
            }},
          {
            "synonym": {
              "type": "synonym",
              "synonyms_path": "synonyms2.txt",
              "ignore_case": true
          }}]
      }
    }
  }
}
},
  "mappings": {
    "animals": {
      "properties": {
        "name": {
          "type": "String",
          "analyzer": "synonym"
        }
      }
    }
  }

我在Chrome中使用JSON Sense尝试了上面的代码片段,但它生成了一个TokenFilter [bool] must have a type associated with it错误。
有没有其他的方法来实现它?

wtlkbnrh

wtlkbnrh1#

analysis区段中的filter区段并不包含查询DSL,而是包含token filter定义。
在您的情况下,需要使用以下设置重新创建索引:

{
  "settings": {
    "index": {
      "analysis": {
        "analyzer": {
          "synonyms": {
            "tokenizer": "whitespace",
            "filter": [
              "synonym1",
              "synonym2"
            ]
          }
        },
        "filter": {
            "synonym1": {
              "type": "synonym",
              "synonyms_path": "synonyms.txt",
              "ignore_case": true
            },
            "synonym2": {
              "type": "synonym",
              "synonyms_path": "synonyms2.txt",
              "ignore_case": true
            }
        }
      }
    }
  },
  "mappings": {
    "animals": {
      "properties": {
        "name": {
          "type": "string",
          "analyzer": "synonyms"
        }
      }
    }
  }
}

相关问题