Elasticsearch在标记化后合并标记(术语)

kokeuurv  于 2023-04-20  发布在  ElasticSearch
关注(0)|答案(1)|浏览(109)

我试图找到一个解决方案,在令牌化后将所有令牌(术语)组合起来。
例如-这个分析器(my-analyser)在应用“custom_stop”过滤器后产生n个令牌。有没有办法合并所有令牌并生成一个令牌?
我见过“指纹”过滤器,它合并了所有的令牌,但它也排序,我不想要。请建议解决方案。

"analysis": {
      "analyzer": {
        "my-analyser": {
          "tokenizer": "standard",
          "filter": [ "custom_stop"]
        }
      },
      "filter": {
        "custom_stop": {
          "type": "stop",
          "ignore_case": true,
          "stopwords": [ "elastic", "aws", "java" ]
        }
}

对于输入-“The concepts in elastic aws java are discussed here”,它将产生这些标记- [“concepts”,“discussed”,“here”],
我想将这三个标记组合起来,生成一个标记,如[“concepts discussed here”]

cuxqih21

cuxqih211#

"analysis": {
  "analyzer": {
    "my-analyzer": {
      "tokenizer": "standard",
      "filter": [
        "custom_stop",
        "concatenate_tokens"
      ]
    }
  },
  "filter": {
    "custom_stop": {
      "type": "stop",
      "ignore_case": true,
      "stopwords": ["elastic", "aws", "java"]
    },
    "concatenate_tokens": {
      "type": "script",
      "script": "String.join(' ', tokens)"
    }
  }
}

相关问题