使用 random_score 的 elasticsearch 会降低性能

标签 elasticsearch

当我在查询中使用random_score时,我发现大约需要150毫秒才能得到查询结果(如果不使用random_score,大约需要250毫秒才能得到结果)。

原始查询

{
"size": 10,
"query": {
    "function_score": {
        "query": {
            "bool": {
                "must": [
                    {
                        "query_string": {
                            "fields": [
                                "sound_title",
                                "album_title"
                            ],
                            "query": "0"
                        }
                    }
                ]
            }
        },
        "functions": [
            {
                "filter": {
                    "bool": {
                        "must": [
                            {
                                "term": {
                                    "sound_chapters": 1
                                }
                            }
                        ]
                    }
                },
                "weight": 1.2
            },
            {
                "field_value_factor": {
                    "field": "album_playcount",
                    "modifier": "log",
                    "missing": "100"
                }
            }
        ],
        "score_mode": "sum"
        }
    }
}

使用 random_score 进行查询

{
"size": 10,
"query": {
    "function_score": {
        "query": {
            "bool": {
                "must": [
                    {
                        "query_string": {
                            "fields": [
                                "sound_title",
                                "album_title"
                            ],
                            "query": "0"
                        }
                    }
                ]
            }
        },
        "functions": [
            {
                "filter": {
                    "bool": {
                        "must": [
                            {
                                "term": {
                                    "sound_chapters": 1
                                }
                            }
                        ]
                    }
                },
                "weight": 1.2
            },
            {
                "field_value_factor": {
                    "field": "album_playcount",
                    "modifier": "log",
                    "missing": "100"
                }
            },
            {
                "random_score": {
                    "seed": "123"
                }
            }
        ],
        "score_mode": "sum"
        }
    }
}

有什么方法可以优化查询以提高更好的性能吗?

最佳答案

如果您要向任何 ElasticSearch 查询添加更多函数,ES 将需要一些处理时间才能将该函数的分数包含到主分数中,从而增加总体时间。 您可以阅读有关 elasticsearch 中的随机评分 here 的更多信息.

提高查询性能的最常见方法是使用过滤器而不是查询,因为过滤器会被缓存。但如果您的服务器中有足够的内存,则应该这样做。

您可以从博客 here 获得更多想法.

关于使用 random_score 的 elasticsearch 会降低性能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38717156/

相关文章:

html - 从HTML搜索和查看Elasticsearch结果

c# - 如何在 Elasticsearch 中使用 Entity Framework

elasticsearch - 如何在kibana 4中每秒制作一个图形滴答

elasticsearch - logstash不够快地输出到elasticsearch

indexing - 是否需要在ElasticSearch文档中使用非常短的字段名称

elasticsearch - 如何在Kibana 4中设计多X轴图

.net - 如何使用Visual Studio解决方案和TFS设置ElasticSearch数据备份?

lucene - Elasticsearch 插件

elasticsearch - ElasticSearch实时地理查询的问题

search - elasticsearch前瞻性搜索解决方案