首页 > 解决方案 > Elasticsearch 语言分析器 - 文本分析后返回检索到的字段

问题描述

  1. 我正在研究 Elasticsearch 中的全文搜索引擎,并在索引时间使用多语言数据。我使用弹性搜索进行文本分析,我希望能够在预处理后返回令牌(检索到的索引)。我知道分析 API,但是对 +200.000 个文档执行此操作非常耗时。我找到了“术语聚合”,但我不确定它是如何工作的。有任何想法吗?

  2. 我用在映射语言分析器中。使用语言分析器或每个文档都通过每个语言分析器时是否有任何开箱即用的语言检测?如果是这样,使用语言检测并为每种语言创建多字段是否有意义?在设置或映射中使用语言分析器有什么区别?

PUT /index_sample
{
  "settings": {
    "analysis" : {
      "analyzer" : {
        "my_analyzer" : {
          "type" : "custom",
          "tokenizer" : "standard",
          "filter" : [
            "my_asciifolding",
            "my_apostrophe",
            "cjk_bigram"]
        }
      },
      "filter" : {
        "my_asciifolding" : {
          "type" : "asciifolding",
          "preserve_original" : true
        },
        "my_apostrophe" :{
        "type" : "apostrophe"
        }
      }
    }
  },
  "mappings" : {
    "properties": {
      "category_number" : {
        "type" : "integer",
        "fields" : {
          "raw" : {
          "type" : "keyword"
          }
        }
      },
      "product": {
        "type" : "text",
        "index" : "true",
        "store" : "true",
        "analyzer" : "my_analyzer",
        "fields" : {
          "german_field": {
            "type" : "text",
            "analyzer": "german"
          },
          "english_field" : {
            "type" : "text",
            "analyzer" : "english"
          },
          "chinese_field" : {
            "type" : "text",
            "analyzer" : "smartcn"
          },
          "spanish_field": {
            "type" : "text",
            "analyzer" : "spanish"
          },
          "czech_analyer" : {
            "type" : "text",
            "analyzer" : "czech"
          },
          "french_field": {
            "type" : "text",
            "analyzer" : "french"
          },
          "italian_field" : {
            "type" : "text",
            "analyzer" : "italian"
          },
          "dutch_field": {
            "type" : "text",
            "analyzer" : "dutch"
          },
          "portuguese_field": {
            "type" : "text",
            "analyzer" : "portuguese"
          }
        }  
      }
    }
  }
}

标签: elasticsearchnlp

解决方案


如果您想查看索引字段的外观,您可以使用 _analysis API(我相信您不想这样做)


或者你可以看看 _termvectors

GET /<index_name>/_termvectors/<doc_id>?fields=<filed_name>

推荐阅读