searchkick/elasticsearch错误:请改用关键字字段或者,在[name]上设置fielddata=true

kyvafyod  于 2021-07-13  发布在  ElasticSearch
关注(0)|答案(0)|浏览(399)

我正在rails应用程序中使用searchkick。我正在清理我的测试,我得到了一个基本的索引页:

Searchkick::InvalidQueryError: [400] {"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"Text fields are not optimised for operations that require per-document field data like aggregations and sorting, so these operations are disabled by default. Please use a keyword field instead. Alternatively, set fielddata=true on [name] in order to load field data by uninverting the inverted index.

我的模型(我添加了多租户复杂性,并尝试了所有这些为可能的解决方案找到的自定义Map):

class Vendor < ApplicationRecord
      multi_tenant :company
      searchkick merge_mappings: true, inheritance: true, index_name: -> { [MultiTenant.current_tenant.tenant_name, model_name.plural, Rails.env].join('_') },
        mappings: {
          properties: {
            name: {
              type: "text",
              fielddata: true,
              fields: {
                keyword: {
                  type: "keyword"
                }
              }
            }
          }
        }

  def search_data
    attributes.merge({
      tracker: tracker_id,
      status: aasm_state,
      comments: comments.map(&:note).join(" "),
      city_es: city.presence ? city : "None",
      province_es: province.presence ? province : "None"
      })
  end

我的控制器 es_ 方法是我在设置这些重复参数值时添加的一些自定义帮助程序:

@vendors = Vendor.search(es_query(),
  limit: es_limit(),
  aggs: { status: {}, city_es: {}, province_es: {} },
  where: where,
  offset: es_offset(),
  order: { es_order_col("name") => { order: es_order_dir(), unmapped_type: "long" }},
  match: :word,
  operator: "or",
  includes: [])

浏览器开发环境运行良好。不知道我错过了什么来修复这个。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题