Elasticsearch-rails,高亮查询

Elasticsearch-rails, highlights query

我正在尝试从 Elasticsearch 中获取亮点 -railsgem,但我无法让它工作。

我的搜索方式:

query = {
  query: {
    filtered: {
      query: {
        match: {
          _all: params[:q]
        }
      },
      filter: {
        term: {
          active: true
        }
      }
    },
  },
  highlight: {
    fields: {
      _all: {fragment_size: 150, number_of_fragments: 3}
    }
  }
}

@results = Elasticsearch::Model.search(query, [Market, Component]).results

当我在视图中映射我的结​​果以检查是否有任何亮点时,我得到一个 false:

的数组
= @results.map(&:highlight?)

我在这里通读了 Elasticsearch 文档:https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-highlighting.html and the gem's documentation here: https://github.com/elastic/elasticsearch-rails/tree/master/elasticsearch-model 我的查询似乎是正确的。不确定如何进行。

显然,解决方案是使用 "*" 而不是 "_all"

query = {
  query: {
    filtered: {
      query: {
        match: {
          _all: params[:q]
        }
      },
      filter: {
        term: {
          active: true
        }
      }
    },
  },
  highlight: {
    tags_schema: "styled",
    fields: {
      :"*" => {}
    }
  }
}