是否可以将more_like_this和聚合结合起来获取类似文档并将其显示为分组?我可以在Elasticsearch中做到吗?
{
"size": 12,
"query": {
"filtered": {
"query": {
"more_like_this": {
"fields": [
"summary_text", "description.orig"
],
"docs": [
{
"_id": "9753"
}enter code here
],
"min_term_freq": 1,
"max_query_terms": 12
}
}
}
},
"aggs": {
"by_product_class": {
"terms": {
"field": "product_class_id"
}
}
}
}
答案 0 :(得分:0)
是。在Elasticsearch 2.3中,您的聚合应该类似于:
{
"size": 12,
"query": {
"more_like_this": {
"fields": ["summary_text", "description.orig"],
"like": [{
"_index": "youIndex",
"_type": "yourType",
"_id": "9753"
}],
"min_term_freq": 1,
"max_query_terms": 12
}
},
"aggs": {
"by_product_class": {
"terms": {
"field": "product_class_id"
}
}
}
}
您可以在"like"
数组中指定多个文档,甚至可以使用"doc": {"field1": x, "field2": y, ...}
动态定义文档。 This是一个很好的参考。