es创建索引的格式,并初始化数据

Posted stono

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了es创建索引的格式,并初始化数据相关的知识,希望对你有一定的参考价值。

es创建索引的格式,并初始化数据

学习了:https://www.imooc.com/video/15759

1, 创建格式
POST 127.0.0.1:9200/book/novel/_mappings
{
    "novel":{
        "properties": {
            "word_count": {
                "type": "integer"
            },
            "author": {
                "type": "keyword"
            },
            "title": {
                "type": "text"
            },
            "publish_date": {
                "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis",
                "type": "date"
            }
        }
    }
}
2,插入数据
PUT 方法进行数据插入,插入同时指定id
127.0.0.1:9200/book/novel/5
{
    "author": "王五",
    "title": "菜谱",
    "word_count": 5000,
    "publish_date": "2002-10-01"
}
127.0.0.1:9200/book/novel/2
{
    "author": "李三",
    "title": "Java入门",
    "word_count": 2000,
    "publish_date": "2010-10-01"
}
127.0.0.1:9200/book/novel/8
{
    "author": "瓦力",
    "title": "ElasticSearch入门",
    "word_count": 3000,
    "publish_date": "2017-08-20"
}
127.0.0.1:9200/book/novel/9
{
    "author": "很胖的瓦力",
    "title": "ElasticSearch精通",
    "word_count": 3000,
    "publish_date": "2017-08-15"
}
127.0.0.1:9200/book/novel/10
{
    "author": "牛魔王",
    "title": "芭蕉扇",
    "word_count": 1000,
    "publish_date": "2000-10-01"
}
127.0.0.1:9200/book/novel/2
{
    "author": "李三",
    "title": "Java入门",
    "word_count": 2000,
    "publish_date": "2010-10-01"
}
127.0.0.1:9200/book/novel/4
{
    "author": "李四",
    "title": "ElasticSearch大法好",
    "word_count": 1000,
    "publish_date": "2017-08-01"
}
127.0.0.1:9200/book/novel/6
{
    "author": "赵六",
    "title": "剑谱",
    "word_count": 10000,
    "publish_date": "1997-01-01"
}
127.0.0.1:9200/book/novel/1
{
    "author": "张三",
    "title": "移魂大法",
    "word_count": 1000,
    "publish_date": "2000-10-01"
}
127.0.0.1:9200/book/novel/7
{
    "author": "张三丰",
    "title": "太极拳",
    "word_count": 1000,
    "publish_date": "1997-01-01"
}
127.0.0.1:9200/book/novel/3
{
    "author": "张四",
    "title": "python入门",
    "word_count": 2000,
    "publish_date": "2005-10-01"
}
127.0.0.1:9200/book/novel/11
{
    "author": "孙悟空",
    "title": "七十二变",
    "word_count": 1000,
    "publish_date": "2000-10-01"
}
127.0.0.1:9200/book/novel/12
{
    "author": "瓦力",
    "title": "瓦力教我们学ElasticSearch",
    "word_count": 1000,
    "publish_date": "2017-08-01"
}
1, 创建格式
POST 127.0.0.1:9200/book/novel/_mappings
{
    "novel":{
        "properties": {
            "word_count": {
                "type": "integer"
            },
            "author": {
                "type": "keyword"
            },
            "title": {
                "type": "text"
            },
            "publish_date": {
                "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis",
                "type": "date"
            }
        }
    }
}
2,插入数据
PUT 方法进行数据插入,插入同时指定id
127.0.0.1:9200/book/novel/5
{
    "author": "王五",
    "title": "菜谱",
    "word_count": 5000,
    "publish_date": "2002-10-01"
}
127.0.0.1:9200/book/novel/2
{
    "author": "李三",
    "title": "Java入门",
    "word_count": 2000,
    "publish_date": "2010-10-01"
}
127.0.0.1:9200/book/novel/8
{
    "author": "瓦力",
    "title": "ElasticSearch入门",
    "word_count": 3000,
    "publish_date": "2017-08-20"
}
127.0.0.1:9200/book/novel/9
{
    "author": "很胖的瓦力",
    "title": "ElasticSearch精通",
    "word_count": 3000,
    "publish_date": "2017-08-15"
}
127.0.0.1:9200/book/novel/10
{
    "author": "牛魔王",
    "title": "芭蕉扇",
    "word_count": 1000,
    "publish_date": "2000-10-01"
}
127.0.0.1:9200/book/novel/2
{
    "author": "李三",
    "title": "Java入门",
    "word_count": 2000,
    "publish_date": "2010-10-01"
}
127.0.0.1:9200/book/novel/4
{
    "author": "李四",
    "title": "ElasticSearch大法好",
    "word_count": 1000,
    "publish_date": "2017-08-01"
}
127.0.0.1:9200/book/novel/6
{
    "author": "赵六",
    "title": "剑谱",
    "word_count": 10000,
    "publish_date": "1997-01-01"
}
127.0.0.1:9200/book/novel/1
{
    "author": "张三",
    "title": "移魂大法",
    "word_count": 1000,
    "publish_date": "2000-10-01"
}
127.0.0.1:9200/book/novel/7
{
    "author": "张三丰",
    "title": "太极拳",
    "word_count": 1000,
    "publish_date": "1997-01-01"
}
127.0.0.1:9200/book/novel/3
{
    "author": "张四",
    "title": "python入门",
    "word_count": 2000,
    "publish_date": "2005-10-01"
}
127.0.0.1:9200/book/novel/11
{
    "author": "孙悟空",
    "title": "七十二变",
    "word_count": 1000,
    "publish_date": "2000-10-01"
}
127.0.0.1:9200/book/novel/12
{
    "author": "瓦力",
    "title": "瓦力教我们学ElasticSearch",
    "word_count": 1000,
    "publish_date": "2017-08-01"
}

 

以上是关于es创建索引的格式,并初始化数据的主要内容,如果未能解决你的问题,请参考以下文章

es关闭索引

es修改索引时间格式

创建es索引-格式化和非格式化

es 创建动态索引(二)

记一次调优过程—Spark读取OBS文件入ES

es可以不创建索引库直接添加文档吗