【问题标题】:Elasticsearch Highlight issue on aggregated fields聚合字段上的 Elasticsearch Highlight 问题
【发布时间】:2016-05-20 06:14:10
【问题描述】:

我正在使用 ElasticSearch,并希望在搜索查询的聚合结果中突出显示字段。

我不想得到搜索查询的结果,所以我将size 保留为0,这只会给我汇总的结果。

现在我想在聚合结果上应用荧光笔,但这不起作用。我使用术语聚合器和热门聚合器作为子聚合器。在 ES 文档中,他们提到了热门聚合器支持突出显示。

我的查询结构是这样的:

{
    size:0,
    query:{
        .......
    },
    aggregation:{
        name-of-agg:{
            term:{
                ....
            },
            aggregation:{
                name-of-sub-agg:{
                    top-hits:{
                        ....
                    }
                }
            }
        },
        highlight:{
            fields:{
                fieldname:{

                }
            }
        }
    }
}

【问题讨论】:

    标签: elasticsearch highlight


    【解决方案1】:

    您必须将highlight inside 设置为top_hits 聚合属性(不在aggregation 内部)。

    这是一个最小的工作示例:

    echo create index
    curl -XPUT 'http://127.0.0.1:9010/files?pretty=1' -d '
    {
      "settings": {
      }
    }'
    echo create type
    curl -XPUT 'http://127.0.0.1:9010/files/_mapping/file?pretty=1' -d'
    {
      "properties":{
        "fileName":{
          "type":"string",
          "term_vector":"with_positions_offsets"
        }
      }
    }
    '
    echo insert files
    curl -XPUT 'http://127.0.0.1:9010/files/file/1?pretty=1' -d'
    {
      "fileName":"quick brown fox"
    }
    '
    echo flush
    curl -XPOST 'http://127.0.0.1:9010/files/_flush?pretty=1'
    echo search brown tophits
    curl -XGET 'http://127.0.0.1:9010/files/file/_search?pretty=1' -d '
    {
      "size" : 0,
      "query":{
        "match":{
          "fileName":"brown"
        }
      },
      "aggregations" : {
        "docs" : {
          "top_hits" : {
            "highlight": {
              "fields": {
                "fileName": {}
              }
            }
          }
        }
      }
    }'
    

    【讨论】:

      猜你喜欢
      • 2023-04-03
      • 1970-01-01
      • 2020-02-18
      • 2014-08-24
      • 2016-09-24
      • 2016-11-23
      • 2015-07-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多