美文网首页
二、Es索引

二、Es索引

作者: yongfutian | 来源:发表于2018-12-30 10:04 被阅读0次

Elasticearch索引

php创建索引语法:
\Elasticsearch\ClientBuilder::create()->build()-indices()->create($params);

1、创建索引

/**
 * 创建常规索引配置参数
 * @return array
 */
public static function create()
{
    return [
        'index' => 'books',
    ];
}

** 2、创建索引、指定类型和映射**

 /**
 * 创建索引、指定类型和映射
 * 建议一个索引对应一个类型
 * @return array
 */
public static function CreateIndexTypeMapping()
{
    return [
        'index' => self::$index,
        'body' => [
            'mappings' => [
                self::$type => [
                    '_source' => [
                        'enabled' => true
                    ],
                    'properties' => [
                        'goods_id' => [
                            'type' => 'integer'
                        ],
                        'goods_name' => [
                            'type' => 'keyword'
                        ],
                    ],
                ],
            ],
        ],
    ];
}

** 3、删除索引**

/**
 * 删除索引
 * @return array
 */
public static function delete()
{
    return [
        'index' => 'books'
    ];
}

** 4、更改索引的配置参数**

 public static function putSettings()
{
    return [
        'index' => self::$index,
        'body' => [
            'settings' => [
                'number_of_replicas' => '0',
                'refresh_interval' => '-1',
            ],
        ],
    ];
}

5、获取索引配置参数

/**
 * 获取索引配置参数
 * @return array
 */
public static function getSettings()
{
    return [
        'index' => self::$index,//获取单个
        'index' => [
            self::$index,'order' //获取多个
        ],
    ];
}

** 6、获取映射信息**

public static function getMappings()
{
    //获取所有的索引和类型映射
    return [];
    //获取某个索引里面的所有类型映射
    return [
        'index' => self::$index
    ];
    //获取所有类型的 eg:goods 的映射,而不考虑索引
    return [
        'type' => self::$type,
    ];
    //获取某个索引的某个类型的映射
    return [
        'index' => self::$index,
        'type' => self::$type
    ];
    //获取多个索引的映射
    return [
        'index' => [
            self::$index,'index2'
        ],
    ];
}

7、更改或增加一个索引的映射

/**
 * 更改或增加一个索引的映射
 * @return array
 */
public static function putMappings()
{
    return [
        'index' => 'books',
        'type' => 'IT',
        'body' => [
            self::$type => [
                '_source' => [
                    'enabled' => true
                ],
                'properties' => [
                    'id' => [
                        'type' => 'integer'
                    ],
                    'author' => [
                        'type' => 'keyword'
                    ],
                    'description' => [
                        'type' => 'text',
                        'fielddata' => true,
                    ],
                    'language' => [
                        'type' => 'keyword'
                    ],
                    'title' => [
                        'type' => 'keyword'
                    ],
                ],
            ],
        ],
    ];
}

相关文章

  • 二、Es索引

    Elasticearch索引 php创建索引语法:\Elasticsearch\ClientBuilder::cr...

  • spark 读取 ES(es.resource配置)

    es.resource 可配置为: ES 别名 单个索引名/doc_type 索引1,索引2,索引3

  • Elasticsearch 7 : 自定义 mapping 和

    ES 7 中在创建索引时指定 Mapping ES 7 中先建索引,再自定义 mapping ES 7 建索引时指...

  • Elasticsearch-基础使用

    零、本文纲要 一、认识Elasticsearch二、倒排索引三、ES的部分概念四、安装ES、Kibana、分词器五...

  • ES 相关语句

    ES: 查看索引 添加 创建索引 创建类型 查询

  • ElasticSearch的基本操作

    操作ES的RESTful语法 索引的操作 1、创建一个索引 2、查看一个索引 3、删除一个索引 3.4 ES中Fi...

  • es 创建动态索引(二)

    上一篇文章es 创建动态索引(一) ,通过el表达式 修改 @Document 里 indexName 值,实现...

  • 二、ES之倒排索引

    说起倒排,要提及一下正排,正排就是我们平时所熟知的,常用的关系库查询就是正排,我们可以根据数据的id获取到这一整条...

  • python对es基础的增删改查

    安装API python对索引进行操作 建立es连接 创建索引 删除索引 判断索引存在 对索引加入mapping ...

  • 4.es基本用法

    一.es基础语法 1.索引curl 索引理解:可以理解成mysql的库,但是es中是没有库这个概念的 es是支持r...

网友评论

      本文标题:二、Es索引

      本文链接:https://www.haomeiwen.com/subject/poamlqtx.html