Draymonders / Code-Life

The marathon continues though.
27 stars 3 forks source link

ES 学习 #133

Open Draymonders opened 3 years ago

Draymonders commented 3 years ago

简介

es 底层基于 Lucene 实现分布式检索, Lucene主要是做分词处理(有各种分词器)

https://www.elastic.co/guide/cn/elasticsearch/guide/current/foreword_id.html

索引

创建索引

如下创建blog的索引

PUT blog
{
  "settings": {
    "number_of_replicas": 1,
    "number_of_shards": 2
  }
}

查看索引的配置

GET blog/_settings

文档

新建文档

PUT blog/_create/1
{
  "id": 1,
  "title": "just a title",
  "create-time": "2021-05-16",
  "content": "测试es新建文档"
}

查看文档

GET blog/_doc/1

检索

全文检索,按照相关性倒序排列

GET blog/_search 
{
  "query": {
    "match": {
      "title": "just"
    }
  }  
}

高亮操作

GET blog/_search 
{
  "query": {
    "match_phrase_prefix": {
      "title": "just"
    }
  },
  "highlight": {
    "fields": {
      "title": {}
    }
  }
}