首页 > 其他分享 >Elastic Stack (二)

Elastic Stack (二)

时间:2022-09-30 21:01:05浏览次数:32  
标签:website 01 Elastic mapping 2019 date article Stack

目录

mapping

映射:自动或手动为index中的_doc建立的一种数据结构和相关配置,简称为mapping映射。

动态映射:dynamic mapping,自动为我们建立index,以及对应的mapping,mapping中包含了每个field对应的数据类型,以及如何分词等设置。

创建索引并插入数据:

PUT /website/_doc/1
{
  "post_date": "2019-01-01",
  "title": "my first article",
  "content": "this is my first article in this website",
  "author_id": 11400
}

PUT /website/_doc/2
{
  "post_date": "2019-01-02",
  "title": "my second article",
  "content": "this is my second article in this website",
  "author_id": 11400
}
 
PUT /website/_doc/3
{
  "post_date": "2019-01-03",
  "title": "my third article",
  "content": "this is my third article in this website",
  "author_id": 11400
}

查看 索引website 的映射类型


GET website/_mapping

尝试各种搜索

GET /website/_search?q=2019        0条结果             
GET /website/_search?q=2019-01-01           1条结果
GET /website/_search?q=post_date:2019-01-01     1条结果
GET /website/_search?q=post_date:2019          0 条结果

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

标签:website,01,Elastic,mapping,2019,date,article,Stack
From: https://www.cnblogs.com/czzz/p/16746227.html

相关文章