概念: 自动或手动为index中的type建立的一种数据结构和相关配置,简称为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条结果
Elasticsearch mapping到底是什么
GET /website/article/_search?q=2017-01-01 3条结果
Elasticsearch mapping到底是什么
GET /website/article/_search?q=post_date:2017-01-01 1条结果
Elasticsearch mapping到底是什么
GET /website/article/_search?q=post_date:2017 1条结果
Elasticsearch mapping到底是什么
查看es自动建立的mapping,带出什么是mapping的知识点
自动或手动为index中的type建立的一种数据结构和相关配置,简称为mapping
像上面直接put数据 会自动 dynamic mapping,自动为我们建立index,创建type,以及type对应的mapping,mapping中包含了每个field对应的数据类型,以及如何分词等设置
也可以手动在创建数据之前,先创建index和type,以及type对应的mapping

GET /website/_mapping/article
Elasticsearch mapping到底是什么
{
“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自动建立mapping的时候,设置了不同的field不同的data type。不同的data type的分词、搜索等行为是不一样的。所以出现了_all field和post_date field的搜索表现完全不一样。

相关文章:

  • 2021-08-04
  • 2021-11-25
  • 2021-06-27
  • 2021-07-01
  • 2021-04-28
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-04
  • 2021-12-18
  • 2021-12-19
  • 2021-11-18
  • 2021-11-22
相关资源
相似解决方案