• 38.mapping小例子


    主要知识点

    初步了解mapping

       

    一,准备数据

    插入几条数据,让es自动为我们建立一个索引

       

    PUT /website/article/1

    {

    "post_date": "2017-01-01",

    "title": "my first article",

    "content": "this is my first article in this website",

    "author_id": 11400

    }

       

    PUT /website/article/2

    {

    "post_date": "2017-01-02",

    "title": "my second article",

    "content": "this is my second article in this website",

    "author_id": 11400

    }

       

    PUT /website/article/3

    {

    "post_date": "2017-01-03",

    "title": "my third article",

    "content": "this is my third article in this website",

    "author_id": 11400

    }

       

    二、尝试各种搜索,并比较搜索结果

    GET /website/article/_search?q=2017                         3条结果

    GET /website/article/_search?q=2017-01-01          3条结果

    GET /website/article/_search?q=post_date:2017-01-01         1条结果

    GET /website/article/_search?q=post_date:2017         1条结果

       

    三,查看typemapping

    GET /website/_mapping/article

    执行结果如下:

    {

    "website": {

    "mappings": {

    "article": {

    "properties": {

    "author_id": {

    "type": "long"

    },

    "content": {

    "type": "text",

    "fields": {

    "keyword": {

    "type": "keyword",

    "ignore_above": 256

    }

    }

    },

    "post_date": {

    "type": "date"

    },

    "title": {

    "type": "text",

    "fields": {

    "keyword": {

    "type": "keyword",

    "ignore_above": 256

    }

    }

    }

    }

    }

    }

    }

    }

    由上结果可以看到es已自动为这个index下的type建立的mapping。es自动或程序员手动为index中的type建立的一种数据结构及其相关配置,简称为mapping。mapping分两种:

    1dynamic mapping,自动为我们建立index,创建type,以及type对应的mappingmapping中包含了每个field对应的数据类型,以及如何分词等设置

    2、手动建立的mapping,也可以手动在创建数据之前,先创建indextype,以及type对应的mapping

       

    四、搜索结果为什么不一致

    因为es自动建立mapping的时候,为不同的field设置了不同的data type。不同的data type的分词、搜索等行为是不一样的。所以出现了_all fieldpost_date field的搜索表现完全不一样。

  • 相关阅读:
    禁用网络连接后无法访问本机数据库的问题
    DevExpress使用笔记
    DEV控件 皮肤问题
    SQLServer2008导入Excel遇到的问题
    InnoSetup使用笔记
    SQLServer清空数据库中所有表的数据
    MS SQL Server2000转换成MySQL
    由MySQL登录不了引发的一些问题
    onerror事件
    DIV+CSS一些小小的技巧
  • 原文地址:https://www.cnblogs.com/liuqianli/p/8468572.html
Copyright © 2020-2023  润新知