Elasticsearch查询性能

Vis*_*hal 6 elasticsearch

我正在使用elasticsearch索引两种类型的对象 -

数据详情

合约对象~60个属性(对象大小 - 120个字节)风险项对象~125个属性(对象大小 - 250个字节)

合同是风险项目的父母(_parent)

我在单个索引中存储了2.4亿个这样的对象(2.1亿个风险项目,3000万个合同)

索引大小为 - 322 gb

群集详细信息

11 m2.4x.large EC2 box [68 gb内存,1.6 TB存储,8个内核](1个盒子是一个负载均衡器节点,node.data = false)50个分片1个副本

elasticsearch.yml

node.data: true
http.enabled: false
index.number_of_shards: 50
index.number_of_replicas: 1
index.translog.flush_threshold_ops: 10000
index.merge.policy.use_compound_files: false
indices.memory.index_buffer_size: 30%
index.refresh_interval: 30s
index.store.type: mmapfs
path.data: /data-xvdf,/data-xvdg
Run Code Online (Sandbox Code Playgroud)

我正在使用以下命令启动elasticsearch节点 - /home/ec2-user/elasticsearch-0.90.2/bin/elasticsearch -f -Xms30g -Xmx30g

我的问题是我正在运行以下关于风险项类型的查询,并且大约需要10-15秒来返回数据,共计20条记录.

我正在以50个并发用户的负载运行它,并且并行发生大约5000个风险项的批量索引负载.

查询(使用加入父子)

HTTP://:9200/contractindex/riskitem/_search*

{
    "query": {
        "has_parent": {
            "parent_type": "contract",
            "query": {
                "range": {
                    "ContractDate": {
                        "gte": "2010-01-01"
                    }
                }
            }
        }
    },
    "filter": {
        "and": [{
            "query": {
                "bool": {
                    "must": [{
                        "query_string": {
                            "fields": ["RiskItemProperty1"],
                            "query": "abc"
                        }
                    },
                    {
                        "query_string": {
                            "fields": ["RiskItemProperty2"],
                            "query": "xyz"
                        }
                    }]
                }
            }
        }]
    }
}
Run Code Online (Sandbox Code Playgroud)

查询来自一个表

Query1(此查询大约需要8秒.)

 <!-- language: lang-json -->

    {
        "query": {
            "constant_score": {
                "filter": {
                    "and": [{
                        "term": {
                            "CommonCharacteristic_BuildingScheme": "BuildingScheme1"
                        }
                    },
                    {
                        "term": {
                            "Address_Admin2Name": "Admin2Name1"
                        }
                    }]
                }
            }
        }
    }



**Query2** (This query takes around 6.5 seconds for Top 10 records ( but has sort on top of it)

 <!-- language: lang-json -->

    {
        "query": {
            "constant_score": {
                "filter": {
                    "and": [{
                        "term": {
                            "Insurer": "Insurer1"
                        }
                    },
                    {
                        "term": {
                            "Status": "Status1"
                        }
                    }]
                }
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

有人可以帮我提高我的查询性能吗?

Sco*_*ice 3

您尝试过自定义路由吗?如果没有自定义路由,您的查询需要在所有 50 个分片中查找您的请求。通过自定义路由,您的查询知道要搜索哪些分片,从而提高查询性能。更多这里

您可以通过在 _routing 字段中包含路由值来为每个批量项目分配自定义路由,如批量 api 文档中所述。