gpt4 book ai didi

Elasticsearch - 加入两种不同类型的文档

转载 作者:行者123 更新时间:2023-12-02 09:26:51 25 4
gpt4 key购买 nike

我有这些文件:

我的电影

{
"_index": "mymovies",
"_type": "mymovie",
"_id": "1",
"_score": 1,
"_source": {
"title" : "Funny title is here"
"genre" : "Comedy"
"movieViews" : 901142
}
}


{
"_index": "mymovies",
"_type": "mymovie",
"_id": "2",
"_score": 1,
"_source": {
"title" : "Sad title is here"
"genre" : "Drama"
"movieViews" : 90
}
}

{
"_index": "mymovies",
"_type": "mymovie",
"_id": "3",
"_score": 1,
"_source": {
"title" : "Sad Second title is here"
"genre" : "Drama"
"movieViews" : 9022
}
}

{
"_index": "mymovies",
"_type": "mymovie",
"_id": "4",
"_score": 1,
"_source": {
"title" : "Horror title is here"
"genre" : "Horror"
"movieViews" : 9022
}
}

用户

{
"Name" : "Doni de brun",
"moviesLiked": [2,1,3]
}
  1. 如何只获取特定用户喜欢的流派?

  2. 是否有更好的方法来组织此查询的数据?

最佳答案

以下查询将完成这项工作:

POST movies/_search
{
"size": 0

, "query": {
"terms": {
"_id": [2,1,3]
}
}

, "aggs": {
"genres_for_user": {
"terms": {
"field": "genre",
"size": 50
}
}
}
}

您的文档结构看起来不错。

确保你有 not_analyzed类型字段的索引。如果您保留此字段的默认分析器,像“经典喜剧”这样的值将被索引为两个关键字,并且在聚合查询中将生成两个计数器,分别用于经典喜剧

关于Elasticsearch - 加入两种不同类型的文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37099984/

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