gpt4 book ai didi

optimization - Elasticsearch查询优化

转载 作者:行者123 更新时间:2023-12-03 00:28:06 24 4
gpt4 key购买 nike

在Elasticsearch中有什么方法可以优化查询?我正在使用以下查询。它的平均15-20s有时是快速4-5s

我的服务器配置:-Centos 6.3,8核16GB RAM

{
"fields": [
"_id",
"aff_id",
"post_uri",
"blog_cat",
"cat_score",
"secondary_cat",
"secondary_cat_score",
"title",
"_score"
],
"min_score": 0.0134,
"query": {
"bool": {
"must": [
{
"query_string": {
"fields": [
"title"
],
"query": "Archery OR Athletics OR Badminton OR Basketball OR Beach Volleyball OR Boxing OR Canoe Slalom OR Canoe Sprint OR Cycling BMX OR Cycling Mountain Bike OR Cycling Road OR Cycling Track OR Diving OR Equestrian / Dressage OR Equestrian / Eventing OR Equestrian / Jumping OR Fencing OR Football OR Golf OR Gymnastics Artistic"
}
}
],
"must_not": [],
"should": []
}
}

我读了有关Elasticsearch查询优化的文章

https://speakerdeck.com/elasticsearch/query-optimization-go-more-faster-better

尝试解决方案更改查询,如下所示,但没有任何区别。
    {
"fields": [
"aff_id",
"post_uri",
"blog_cat",
"cat_score",
"secondary_cat",
"secondary_cat_score",
"title"
],
"query": {
"filtered": {
"query": {
"bool": {
"must": [
{
"term": {
"url.cat": "sports"
}
},
{
"range": {
"main_cat.sports": {
"gte": ".15"
}
}
}
]
}
},
"filter": {
"query": {
"query_string": {
"fields": [
"body",
"title"
],
"query": "Archery OR Athletics OR Badminton OR Basketball OR Beach Volleyball OR Boxing OR Canoe Slalom OR Canoe Sprint OR Cycling BMX OR Cycling Mountain Bike OR Cycling Road OR Cycling Track OR Diving OR Equestrian / Dressage OR Equestrian / Eventing OR Equestrian / Jumping OR Fencing OR Football OR Golf OR Gymnastics Artistic"
}
}
}
}
},
"from": 0,
"size": 1000
}

注意:我正在使用默认分析器,但尚未定义自定义分析器。

最佳答案

这是查询的优化版本:-

变化:-

1)在查询中使用filters,将filter缓存。
2)默认情况下,不缓存query_string/query过滤器,但我们可以通过设置_cache: true将其打开。

{
"fields": [
"aff_id",
"post_uri",
"blog_cat",
"cat_score",
"secondary_cat",
"secondary_cat_score",
"title"
],
"query": {
"filtered": {
"filter": {
"bool": {
"must": [
{
"term": {
"url.cat": "sports"
}
},
{
"range": {
"main_cat.sports": {
"gte": ".15"
}
}
},
{
"fquery": {
"query": {
"query_string": {
"fields": [
"body",
"title"
],
"query": "Archery OR Athletics OR Badminton OR Basketball OR Beach Volleyball OR Boxing OR Canoe Slalom OR Canoe Sprint OR Cycling BMX OR Cycling Mountain Bike OR Cycling Road OR Cycling Track OR Diving OR Equestrian / Dressage OR Equestrian / Eventing OR Equestrian / Jumping OR Fencing OR Football OR Golf OR Gymnastics Artisti"
}
},
"_cache": true
}
}
]
}
}
}
},
"from": 0,
"size": 1000,
"sort": [
{
"_uid": "desc"
}
]
}

关于optimization - Elasticsearch查询优化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21703909/

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