首页 文章

未能在[synonym]下找到全局令牌过滤器

提问于
浏览
0

因此,从this page的文档中,似乎我可以使用分析API从标记化器,令牌过滤器和字符过滤器构建自定义瞬态分析器,并根据我的示例文本对其进行测试 .

目标是我想看看synonym token filter是否满足我的需求,哪些术语被标记为同义词,哪些术语不被标记为同义词 .

但是,当我这样做

curl -XGET'localhost:9200 / _analyze?char_filters = html_strip&tokenizer = whitespace&token_filters = synonym'-d'man and male are same'

我得到了,而不是得到结果

{
  "error": "ElasticsearchIllegalArgumentException[failed to find global token filter under [synonym]]",
  "status": 400
}

我在这里做错了什么想法?

1 回答

  • 0

    目前无法使用ad-hoc同义词令牌过滤器,因为实现需要访问"to the tokenizer factories for the index."(请参阅elasticsearch Github issue . )不幸的是,此限制目前没有记录docs on using custom token filters on the _analyze endpoint

    以下是使用重新打开索引的方法创建和更新同义词标记过滤器的一些示例命令:

    # create index with filter
    curl -v -X PUT -s -H 'Content-Type: application/json' 'localhost:9200/syn_test_idx' -d '
    {
      "settings" : {
        "analysis" : {
          "filter" : {
            "test_synonym_filter" : {
              "type" : "synonym",
              "synonyms" : [
                "i-pod, i pod => ipod",
                "universe, cosmos"
              ]
            }
          }
        }
      }
    }
    
    # test token filter
    ' | jq .
    curl -X POST -s -H 'Content-Type: application/json' 'localhost:9200/syn_test_idx/_analyze' -d '{
      "tokenizer": "standard",
      "filter": ["global_synonym_filter"],
      "text": "cow i phone"
    }' | jq .
    

    (“我的手机”未被同义词列表捕获 . )

    # update index
    curl -X POST -s 'localhost:9200/syn_test_idx/_close' | jq .
    curl -X PUT -s -H 'Content-Type: application/json' 'localhost:9200/syn_test_idx/_settings' -d '{
      "analysis" : {
        "filter": {
          "test_synonym_filter":{
            "type":"synonym",
            "synonyms" : [
              "i-pod, i pod => ipod",
              "universe, cosmos",
              "i-phone, i phone => iphone"
            ]
          }
        }
      }
    }' | jq .
    curl -X POST -s 'localhost:9200/syn_test_idx/_open' | jq .
    
    # test token filter
    ' | jq .
    curl -X POST -s -H 'Content-Type: application/json' 'localhost:9200/syn_test_idx/_analyze' -d '{
      "tokenizer": "standard",
      "filter": ["global_synonym_filter"],
      "text": "cow i phone"
    }' | jq .
    

    (“我的电话”由同义词列表翻译成“iphone” . )

    (在一个不相关的说明中,我的zsh / YADR设置由于某种原因没有显示帖子响应主体,因此我通过 jq 进行管道传输 . )

相关问题