【问题标题】:Penalizing documents in facet results based on their content根据内容在构面结果中对文档进行惩罚
【发布时间】:2013-11-28 10:51:50
【问题描述】:

如果我们在elasticsearch中有以下文档:

[
    {'name': 'John', 'time': '2013-01-01 12:01:00'},
    {'name': 'John', 'time': '2013-01-01 12:02:00'},
    {'name': 'John', 'time': '2013-01-01 12:03:00'},
    {'name': 'John', 'time': '2013-01-01 12:04:00'},
    {'name': 'Harry', 'time': '2013-01-01 12:05:00'},
    {'name': 'Fred', 'time': '2013-01-01 12:06:00'},
    {'name': 'Fred', 'time': '2013-01-01 12:07:00'}
]

我们对“名称”字段进行分面,我们会得到这样的结果:

 "facets": {
   "count_per_name": {
      "_type": "terms",
      "missing": 0,
      "total": 7,
      "other": 0,
      "terms": [
         {
            "term": "John",
            "count": 4
         },
         {
            "term": "Fred",
            "count": 2
         },
         {
            "term": "Harry",
            "count": 1
         }
      ]
   }
}

我的问题是:是否可以在 elasticsearch 中执行分面查询,从而将具有name“John”的那些文档算作“一半”文档?这将导致 John 的计数从 4 下降到 2,但 Fred 和 Harry 保持不变:

 "facets": {
   "count_per_name": {
      "_type": "terms",
      "missing": 0,
      "total": 5,
      "other": 0,
      "terms": [
         {
            "term": "John",
            "count": 2
         },
         {
            "term": "Fred",
            "count": 2
         },
         {
            "term": "Harry",
            "count": 1
         }
      ]
   }
}

【问题讨论】:

    标签: search elasticsearch faceted-search facet


    【解决方案1】:

    你可以和http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-facets-terms-stats-facet.html一起玩

    并指定 value_script,其中 John 返回 0.5,其他人返回 1,并使用 SUM facet 结果进行操作。虽然这种方法会影响性能

    【讨论】:

      猜你喜欢
      • 2012-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-07
      • 1970-01-01
      • 2016-05-05
      • 1970-01-01
      • 2013-09-30
      相关资源
      最近更新 更多