我在为我的音像店建一个搜索引擎。
我只对音频文档使用了一个索引,如下所示:
{
id: { type: 'integer' },
title: { type: 'search_as_you_type' },
description: { type: 'text' },
createdAt: { type: 'date' },
updatedAt: { type: 'date' },
datePublished: { type: 'date' },
duration: { type: 'float' },
categories: {
type: 'nested',
properties: {
id: { type: 'integer' },
name: { type: 'text' }
},
}
}
通过文本搜索音频文档和发布日期的订单是很简单的。但是,我想通过基于特定范围内的音频听音时间和购买历史来进行文本搜索和排序,例如:过去3个月或过去30天的文本搜索趋势音频,因此我调整了结构如下:
{
...previousProperties,
listenTimes: {
type: 'nested',
properties: {
timestamp: { type: 'date' },
progress: { type: 'float' }, // value 0-1.
},
},
purchaseHistories: {
type: 'nested',
properties: {
timestamp: { type: 'date' }
},
},
}
这是我在过去3个月里获取最新音频的查询,它成功了:
{
bool: {
should: [
{
nested: {
path: 'listenTimes',
query: {
function_score: {
query: {
range: {
'listenTimes.timestamp': {
gte: $range,
},
},
},
functions: [
{
field_value_factor: {
field: 'listenTimes.progress',
missing: 0,
},
},
],
boost_mode: 'replace',
},
},
score_mode: 'sum',
},
},
{
nested: {
path: 'purchaseHistories',
query: {
function_score: {
query: {
range: {
'purchaseHistories.timestamp': {
gte: 'now+1d-3M/d',
},
},
},
boost: 1.5,
},
},
score_mode: 'sum',
},
},
],
},
}
我的方法有些不确定,例如:
我对Elasticsearch非常陌生,所以有谁能给我一些关于这个案子的建议,非常感谢!
发布于 2021-07-11 16:45:54
第一个问题是好的,它取决于您将如何实现它,您将不得不注意原子操作,因为,我猜,您正在计划获取侦听次数,然后保存递增的值。如果您在一个线程中从一个应用程序中执行此操作,并且它正在设法及时处理它,那么您很好,但是您无法进行扩展。我要说的是,elasticsearch并不真正适用于这类交易。第一个出现在我大脑中的想法是将数字保存到SQL数据库中,并按计划更新elasticsearch。我想这些结果不需要实时更新吧?
关于第二个问题,我将发布来自elasticsearch文档The document must still be reindexed, but using update removes some network roundtrips and reduces chances of version conflicts between the GET and the index operation.
的引文,您可以在这个链接上找到更多信息。
https://stackoverflow.com/questions/68338030
复制相似问题