ElasticSearch最佳入门实践(三十七)用一个例子告诉你 mapping 到底是什么

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_33746789/article/details/83783295

1、插入几条数据

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
}

2、各种搜索

在这里插入图片描述

3、查看es自动建立的mapping

在这里插入图片描述

自动或手动为index中的type建立的一种数据结构和相关配置,简称为mapping
dynamic mapping,自动为我们建立index,创建type,以及type对应的mapping,mapping中包含了每个field对应的数据类型,以及如何分词等设置,也可以手动在创建数据之前,先创建index和type,以及type对应的mapping

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

猜你喜欢

转载自blog.csdn.net/qq_33746789/article/details/83783295