ES实战-book笔记1

bash 复制代码
#索引一个文档,-XPUT手动创建索引,
curl -XPUT 'localhost:9200/get-together/_doc/1?pretty' -H 'Content-Type: application/json' -d '{
  "name": "Elasticsearch Denver",
  "organizer": "Lee"
}'
#返回结果
{
  "_index" : "get-together",
  "_id" : "1",
  "_version" : 2,
  "result" : "updated",
  "_shards" : {
    "total" : 2,
    "successful" : 1,
    "failed" : 0
  },
  "_seq_no" : 1,
  "_primary_term" : 1
}
#kibana 请求
GET /get-together/_search
#响应:
{
  "took": 277,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 1,
      "relation": "eq"
    },
    "max_score": 1,
    "hits": [
      {
        "_index": "get-together",
        "_id": "1",
        "_score": 1,
        "_source": {
          "name": "Elasticsearch Denver",
          "organizer": "Lee"
        }
      }
    ]
  }
}
#在kibana 中获取索引的映射_mapping
GET /get-together/_mapping
#响应:
{
  "get-together": {
    "mappings": {
      "properties": {
        "name": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "organizer": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        }
      }
    }
  }
}

#通过curl获取一个索引的映射_mapping

bash 复制代码
#查询出至少含有两个关键词的文档
GET /get-together/_search
{
  "query": {
    "bool": {
      "should": [
        { "term": { "tags": "jvm" } },
        { "term": { "tags": "hadoop" } },
        { "term": { "tags": "java" } }
      ],
      "minimum_should_match": 2
    }
  },
  "_source": ["name", "tags"]
}
bash 复制代码
#搜索同时包含Elasticsearch 和 Denver关键词的文档
GET /get-together/_search
{
  "query": {
    "match": {
      "name": {
        "query": "Elasticsearch Denver",
        "operator": "and"
      }
    }
  }
}
bash 复制代码
#词组查询 match_phrase
GET /get-together/_search
{
  "query": {
    "match_phrase": {
      "name": { 
      "query": "enterprise london",
      "slop": 1
      }
    }
  },
  "_source": ["name","description"]
}
bash 复制代码
#搜索词匹配前缀返回高亮提示
GET /get-together/_search
{
  "query": {
    "match_phrase_prefix": {
      "description": {
        "query": "Elasticsearch bas",
        "max_expansions": 2
      }
    }
  },
  "_source": ["name","description"]
}
bash 复制代码
#同时在多个字段中搜索某个字符串multi_match
GET /get-together/_search
{
  "query": {
    "multi_match": {
      "query": "elasticsearch hadoop",
      "fields": ["name","description"]
    }
  }
}
相关推荐
青岛前景互联信息技术有限公司16 小时前
OpenClaw 重构智慧消防:AI时代的平台融合实践
大数据·人工智能
梦梦代码精17 小时前
BuildingAI 上部署自定义工作流智能体:5 个实用技巧
大数据·人工智能·算法·开源软件
极客老王说Agent17 小时前
2026智造前瞻:实在Agent生产排期智能助理核心功能与使用方法详解
大数据·人工智能·ai·chatgpt
问心无愧051318 小时前
ctf show web入门37
笔记
羊群智妍19 小时前
2026生成式AI搜索优化:GEO监测工具全解析
笔记
数智化精益手记局19 小时前
什么是设备维护管理?设备维护管理包含哪些内容?
大数据·网络·人工智能·安全·信息可视化
AllData公司负责人19 小时前
通过Postgresql同步到Doris,全视角演示AllData数据中台核心功能效果,涵盖:数据入湖仓,数据同步,数据处理,数据服务,BI可视化驾驶舱
java·大数据·数据库·数据仓库·人工智能·python·postgresql
桃花键神20 小时前
Bright Data Web Scraping指南 2026: 使用 MCP + Dify 自动采集海外社交媒体数据
大数据·前端·人工智能
koo36420 小时前
周报5.10
笔记
kdxiaojie21 小时前
U-Boot分析【学习笔记】(3)
linux·笔记·学习