1

我有一个对象被索引到带有大型附件的 Elasticsearch 中,我不想将其存储在 _source 中。在映射中指定“排除”修复了该问题(感谢此处回答的另一个问题),但是当我为过滤器/分析器添加自定义设置时,它以某种方式破坏了排除,我想知道这是轮胎问题还是它只需要以不同的方式指定排除。

这是代码:

settings analysis: {
  filter: {
    ngram_filter: {
      type: "nGram",
      min_gram: 2,
      max_gram: 12
    }
  },
  index_analyzer: {
    index_ngram_analyzer: {
      type: "custom",
      tokenizer: "standard",
      filter: ["lowercase", "ngram_filter"]
    }
  },
  search_analyzer: {
    search_ngram_analyzer: {
      type: "custom",
      tokenizer: "standard",
      filter: ["standard", "lowercase", "ngram_filter"]
    }
  }
} do
  mapping :_source => { :excludes => ['attachment'] } do
    indexes :id, :type => 'integer'
    [:title, :abstract].each do |attribute|
      indexes attribute, type: 'string', analyzer: 'ngram_analyzer'
    end
    indexes :attachment, :type => 'attachment'
  end
end

带有 ":excludes" 的 "mapping" 行一直在起作用,直到我添加了 "settings" 块,所以这导致排除被忽略。有什么想法吗?提前致谢!

4

1 回答 1

3

试试这个:

settings :analysis => {
  :filter  => {
    :ngram_filter => {
      :type => "nGram",
      :min_gram => 2,
      :max_gram => 12
    }
  },
  :analyzer => {
    :index_ngram_analyzer => {
      :type  => "custom",
      :tokenizer  => "standard",
      :filter  => ["lowercase", "ngram_filter"]
    },
    :search_ngram_analyzer => {
      :type  => "custom",
      :tokenizer  => "standard",
      :filter  => ["standard", "lowercase", "ngram_filter"]
    }
  }
} do
  mapping :_source => { :excludes => ['attachment'] } do
    indexes :id, :type => 'integer'
    [:title, :abstract].each do |attribute|
      indexes attribute, :type => 'string', :index_analyzer => 'index_ngram_analyzer', :search_analyzer => 'search_ngram_analyzer'
    end
    indexes :attachment, :type => 'attachment'
  end
end
于 2012-08-11T02:44:10.980 回答