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"]
    }
  }
}
相关推荐
字节跳动数据平台3 小时前
代码量减少 70%、GPU 利用率达 95%:火山引擎多模态数据湖如何释放模思智能的算法生产力
大数据
得物技术4 小时前
深入剖析Spark UI界面:参数与界面详解|得物技术
大数据·后端·spark
武子康6 小时前
大数据-238 离线数仓 - 广告业务 Hive分析实战:ADS 点击率、购买率与 Top100 排名避坑
大数据·后端·apache hive
武子康1 天前
大数据-237 离线数仓 - Hive 广告业务实战:ODS→DWD 事件解析、广告明细与转化分析落地
大数据·后端·apache hive
大大大大晴天1 天前
Flink生产问题排障-Kryo serializer scala extensions are not available
大数据·flink
Elasticsearch2 天前
如何使用 Agent Builder 排查 Kubernetes Pod 重启和 OOMKilled 事件
elasticsearch
Elasticsearch3 天前
通用表达式语言 ( CEL ): CEL 输入如何改进 Elastic Agent 集成中的数据收集
elasticsearch
武子康3 天前
大数据-236 离线数仓 - 会员指标验证、DataX 导出与广告业务 ODS/DWD/ADS 全流程
大数据·后端·apache hive
武子康4 天前
大数据-235 离线数仓 - 实战:Flume+HDFS+Hive 搭建 ODS/DWD/DWS/ADS 会员分析链路
大数据·后端·apache hive
DianSan_ERP5 天前
电商API接口全链路监控:构建坚不可摧的线上运维防线
大数据·运维·网络·人工智能·git·servlet