优化弹性搜索查询

时间:2019-03-27 12:56:18

标签: elasticsearch elasticsearch-aggregation

我最近添加了elasticsearch作为项目的搜索引擎,这是一个电子商务结构模型,我用它来加载类别,制造商等。

查询通常运行非常快,大约200毫秒,考虑到我拥有的产品数量,在某些项目中我拥有超过100万个产品,这是相当不错的。

但是在某些情况下,例如在一个简单的类别页面上,该类别页面中有大约550k产品,查询大约需要500毫秒,我想知道是否可以对其进行优化以使其更快。

请不要根据客户选择的选项在查询中添加聚合和更多过滤器,但是出于优化目的,我删除了它们,因为无论有没有加载,我都具有相同的加载速度。

这是在特定情况下大约需要500-600毫秒的查询

    Array
   (
    [size] => 48
    [from] => 0
    [sort] => Array
        (
            [date_upd] => Array
                (
                    [order] => desc
                )

        )

    [query] => Array
        (
            [bool] => Array
                (
                    [filter] => Array
                        (
                            [0] => Array
                                (
                                    [term] => Array
                                        (
                                            [id_product_categories] => 38231
                                        )

                                )

                        )

                )

        )

)

elasticsearch索引结构如下:         $ data = array(

                'settings' =>

                            array(
                                'number_of_shards' => 1,
                                'number_of_replicas' => 0,
                                'analysis' => $analysis,
                                'index' => array(
                                        'sort.field' => array('date_add','date_upd', 'reduction_percent','price'),
                                        'sort.order' => array('desc','desc','desc','desc')
                                )
                            ),

                'mappings' =>  array( 
                'product' => array(         
                                            //'type' => 'product',
                                            '_all' => array( 'enabled' => false),
                                            'properties' => array
                                                                (
                                                                    'id_product' => array(
                                                                        'type' => 'integer'),

                                                                    'id_image' =>array(
                                                                        'type' => 'integer', 
                                                                        'null_value' => 0 
                                                                    ),

                                                                    'id_supplier' => array(
                                                                        'type' => 'keyword', 
                                                                        'null_value' => 0,
                                                                        'index' => true,
                                                                        'eager_global_ordinals' => true
                                                                    ),

                                                                    'id_manufacturer' => array(
                                                                        'type' => 'keyword', 
                                                                        'null_value' => 0,
                                                                        'index' => true,
                                                                        'eager_global_ordinals' => true
                                                                    ),

                                                                    'id_color' => array(
                                                                        'type' => 'keyword', 
                                                                        'null_value' => 0,
                                                                        'index' => true,
                                                                        'eager_global_ordinals' => true
                                                                    ),

                                                                    'rating' => array(
                                                                        'type' => 'keyword', 
                                                                        'null_value' => 0,
                                                                        'index' => true,
                                                                    ),

                                                                    'id_default_category' => array(
                                                                        'type' => 'integer', 
                                                                        'null_value' => 0 
                                                                    ),



                                                                    'popularity' => array(
                                                                        'type' => 'integer', 
                                                                        'null_value' => 0
                                                                        ),

                                                                    'reduction_percent' => array(
                                                                        'type' => 'integer', 
                                                                        'null_value' => 0,
                                                                        'index' => true
                                                                    ),

                                                                    'is_reduced' => array(
                                                                        'type' => 'boolean'
                                                                    ),

                                                                    'reference' => array(
                                                                        'type' => 'keyword', 
                                                                        'null_value' => 0,
                                                                        'index' => true,

                                                                        ),

                                                                    'image_cover' => array(
                                                                        'type' => 'keyword',
                                                                        'index' => false,
                                                                        ),

                                                                    'image_title' => array(
                                                                        'type' => 'keyword',
                                                                        'index' => false,
                                                                        ),

                                                                    'product_link_title' => array(
                                                                        'type' => 'keyword',
                                                                        'index' => false,
                                                                        ),

                                                                    'price' => array(
                                                                        'type' => 'integer', 
                                                                        'null_value' => 0,
                                                                        'index' => true
                                                                    ),

                                                                    'old_price' => array(
                                                                        'type' => 'float', 
                                                                        'null_value' => 0 
                                                                    ),

                                                                    'id_product_categories' => array(
                                                                        'type' => 'keyword', 
                                                                        'null_value' => 0,
                                                                        'index' => true,
                                                                        'eager_global_ordinals' => true
                                                                    ),

                                                                    'date_add' => array(
                                                                        'type' => 'date',
                                                                        'format' => 'yyyy-MM-dd HH:mm:ss',
                                                                        'index' => true
                                                                        ),

                                                                    'date_upd' => array(
                                                                        'type' => 'date',
                                                                        'format' => 'yyyy-MM-dd HH:mm:ss'
                                                                        ),

                                                                    'product_name' => array(
                                                                        'type' => 'text',
                                                                        "analyzer" =>  $lang_iso_code .'_analyzer'
                                                                    ),
                                                                    'product_heading' => array(
                                                                        'type' => 'keyword',
                                                                        "index" =>  false
                                                                    ),
                                                                    /*
                                                                    'product_description' => array(
                                                                        'type' => 'text',
                                                                        "analyzer" =>  $lang_iso_code .'_analyzer'
                                                                    ),
                                                                    */
                                                                    'product_color' => array(
                                                                        'type' => 'text',
                                                                        "analyzer" =>  $lang_iso_code .'_analyzer'
                                                                    ),
                                                                    'product_categories' => array(
                                                                        'type' => 'text', 
                                                                        "analyzer" =>  $lang_iso_code .'_analyzer'
                                                                    ),
                                                                    'product_manufacturer' => array(
                                                                        'type' => 'text',

                                                                    ),

                                                                    'product_supplier' => array(
                                                                        'type' => 'text'
                                                                    ),

                                                                    'product_link' => array(
                                                                        'type' => 'keyword',
                                                                        'index' => false

                                                                    )


                                                                )
                                        )
                    )
            );

0 个答案:

没有答案