Skip to content

Elasticsearch 笔记

IK 分词器

https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.16.3/elasticsearch-analysis-ik-7.16.3.zip

跨域配置

yaml
# 跨域配置
http.cors.enabled: true
http.cors.allow-origin: "*"
# 跨域配置
http.cors.enabled: true
http.cors.allow-origin: "*"

禁用 geo 数据库

yaml
ingest.geoip.downloader.enabled: false
ingest.geoip.downloader.enabled: false

GUI

https://github.com/cars10/elasticvue

创建 mapping

bash
PUT http://localhost:9200/index/_mapping
PUT http://localhost:9200/index/_mapping
json
{
  "properties": {
    "content": {
      "type": "text",
      "fields": {
        "keyword": {
          "type": "keyword"
        }
      }
    }
  }
}
{
  "properties": {
    "content": {
      "type": "text",
      "fields": {
        "keyword": {
          "type": "keyword"
        }
      }
    }
  }
}

插入示例(自动 ID)

bash
POST http://localhost:9200/index/_doc
Content-Type: application/json
POST http://localhost:9200/index/_doc
Content-Type: application/json
json
{
  "content": "这是用于测试的数据"
}
{
  "content": "这是用于测试的数据"
}

插入或覆盖示例

bash
POST http://localhost:9200/index/_doc/<id>
Content-Type: application/json
POST http://localhost:9200/index/_doc/<id>
Content-Type: application/json
json
{
  "content": "这是用于测试的数据"
}
{
  "content": "这是用于测试的数据"
}

检索示例

bash
POST http://localhost:9200/index/_search
POST http://localhost:9200/index/_search
json
{
  "query": {
    "match": {
      "content": "这是用于测"
    }
  },
  "size": 10,
  "from": 0,
  "sort": []
}
{
  "query": {
    "match": {
      "content": "这是用于测"
    }
  },
  "size": 10,
  "from": 0,
  "sort": []
}
json
{
  "query": {
    "wildcard": {
      "content.keyword": "*这是用于测*"
    }
  },
  "size": 10,
  "from": 0,
  "sort": []
}
{
  "query": {
    "wildcard": {
      "content.keyword": "*这是用于测*"
    }
  },
  "size": 10,
  "from": 0,
  "sort": []
}

精确匹配

json
{
  "query": {
    "bool": {
      "filter": {
        "term": {
          "字段名.keyword": "字段值"
        }
      }
    }
  }
}
{
  "query": {
    "bool": {
      "filter": {
        "term": {
          "字段名.keyword": "字段值"
        }
      }
    }
  }
}

删除示例

bash
DELETE http://localhost:9200/demo
DELETE http://localhost:9200/demo

最后编辑时间:

Version 4.0 (framework-1.0.0-rc.20)