ElasticSearch计算来自两个字段的术语(聚合)

时间:2015-10-05 11:19:53

标签: node.js elasticsearch aggregation

我正在尝试使用ElasticSearch索引中的两个字段创建一个词云。

我目前的代码:

var excludeWords = [
  'on', 'in', 'the', 'a', 'at'
];

client.search({
  index: indexName,
  type: "item",
  searchType: "count",
  body: {
    "query": {"match_all": {}},
    "aggs": {
      "description_words": {
        "terms": {
          "field": "description",
          "exclude": excludeWords,
          "size": 100
        }
      },
      "summary_words": {
        "terms": {
          "field": "summary",
          "exclude": excludeWords,
          "size": 100
        }
      }
    }
  }
}).then(function (resp) {
  res.json(resp);
}, function (err) {
  console.log(err);
});

使用此代码,我将获得两个聚合结果description_words和summary_words以及字数。

是否有可能使用ES聚合来组合这些结果,所以如果description_words聚合有单词“dog”10次而summary_words有“dog”2次,那么它会给我一个组合聚合,其中“dog”计数是12?< / p>

第二件事 - 我需要从上面的代码的摘要和描述字段中删除我的nGram分析器,以便工作summary.raw和description.raw魔法由于某些原因不起作用。有什么建议吗?

0 个答案:

没有答案
相关问题