gpt4 book ai didi

php - 类型的聚合计数过滤器

转载 作者:行者123 更新时间:2023-12-03 02:32:16 25 4
gpt4 key购买 nike

搜索 Elasticsearch 后,我想计算实体中的ID。但是我想计算entities.fk_entity_type = 1或entities.fk_entity_type =2。我该怎么做?

GET smartinfo/_search
{
"query": {
"bool": {
"filter": {
"bool": {
"must": [
{
"term": {
"is_original": 1
}
},
{
"range": {
"date": {
"gte": "2019-12-01 00:00:00",
"lte": "2019-12-31 23:59:59"
}
}
},
{
"term": {
"entities.id": "4683313"
}
}
]
}
}
}
},
"sort": [
{
"id": {
"order": "asc"
}
}
],
"aggs": {
"entids": {
"terms": {
"field": "entities.id",
"size": 10,
"order": {
"_count": "desc"
}
}
}
},
"from": 0,
"size": 1
}

我从elasticsearch的输出
{
"took" : 20,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 10000,
"relation" : "gte"
},
"max_score" : null,
"hits" : [
{
"_index" : "smartinfo",
"_type" : "_doc",
"_id" : "1416597",
"_score" : null,
"_source" : {
"id" : 1416597,
"fk_article_type" : 3,
"fk_article_source" : 11,
"is_original" : 1,
"fk_article_source_type" : 1,
"sentiment" : 0,
"title" : "“Azərbaycanda oynamaqdan qürur duyacağıq” - Nihat Özdemir",
"link" : "https://qafqazinfo.az/news/detail/azerbaycanda-oynamaqdan-qurur-duyacagiq-nihat-ozdemir-271085",
"date" : "2019-12-01 06:12:17",
"entities" : [
{
"id" : 4683312,
"fk_entity_type" : 2
},
{
"id" : 4683325,
"fk_entity_type" : 2
},
{
"id" : 4683314,
"fk_entity_type" : 2
},
{
"id" : 4683313,
"fk_entity_type" : 2
},
{
"id" : 4684170,
"fk_entity_type" : 2
},
{
"id" : 4704179,
"fk_entity_type" : 1
},
{
"id" : 4689748,
"fk_entity_type" : 3
},
{
"id" : 4178204,
"fk_entity_type" : 4
},
{
"id" : 4689840,
"fk_entity_type" : 3
},
{
"id" : 3985091,
"fk_entity_type" : 4
}
]
},
"sort" : [
1416597
]
}
]
},
"aggregations" : {
"entids" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 140334,
"buckets" : [
{
"key" : 4683313,
"doc_count" : 10592
},
{
"key" : 4683314,
"doc_count" : 3240
},
{
"key" : 3970247,
"doc_count" : 1766
},
{
"key" : 4683425,
"doc_count" : 1653
},
{
"key" : 4683312,
"doc_count" : 1516
},
{
"key" : 4683342,
"doc_count" : 1476
},
{
"key" : 4683602,
"doc_count" : 1149
},
{
"key" : 4683316,
"doc_count" : 1137
},
{
"key" : 4683362,
"doc_count" : 901
},
{
"key" : 4683356,
"doc_count" : 812
}
]
}
}
}

我从 flex seach查询。
请帮助我。我需要使用实体过滤总计数。
fk_entity_type。如何执行此操作?

最佳答案

我修复了它,为实体添加了新的映射。 “type”:“嵌套”。

我的过滤器

GET smartinfo3/_search
{
"query": {
"bool": {
"filter": {
"bool": {
"must": [
{
"term": {
"is_original": 1
}
}
]
}
}
}
},
"sort": [
{
"id": {
"order": "asc"
}
}
],
"aggs": {
"entids": {
"nested": {
"path": "entities"
},
"aggs": {
"inner": {
"filter": {
"terms": {
"entities.fk_entity_type": [
1
]
}
},
"aggs": {
"events.id": {
"terms": {
"field": "entities.id",
"size": 100,
"order": {
"_count": "desc"
}
}
}
}
}
}
}
},
"from": 0,
"size": 0
}

关于php - 类型的聚合计数过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59658853/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com