zoukankan      html  css  js  c++  java
  • 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的搜索表现完全不一样。

  • 相关阅读:
    索引器
    异常
    C#各版本
    构造函数
    值类型和引用类型
    面向对象聊天机器人
    linux 系统快捷键
    linux 系统常用设置
    linux 系统介绍
    linux 命令学习.txt
  • 原文地址:https://www.cnblogs.com/liuqianli/p/8468572.html
Copyright © 2011-2022 走看看