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"]
    }
  }
}
相关推荐
wdfk_prog30 分钟前
[Linux]学习笔记系列 -- [fs]kernfs
linux·笔记·学习
代码游侠37 分钟前
学习笔记——IO多路复用技术
linux·运维·数据库·笔记·网络协议·学习
wang_yb44 分钟前
数据分析师的“水晶球”:时间序列分析
大数据·databook
ModestCoder_1 小时前
Git 版本管理教程
大数据·git·elasticsearch
hg01181 小时前
湖南工程机械海外火爆,非洲成为出口新增长极
大数据
QT 小鲜肉1 小时前
【Linux命令大全】001.文件管理之mattrib命令(实操篇)
linux·运维·服务器·chrome·笔记
乐迪信息2 小时前
乐迪信息:异物入侵识别算法上线,AI摄像机保障智慧煤矿生产稳定
大数据·运维·人工智能·物联网·安全
熬夜敲代码的小N2 小时前
从SEO到GEO:AI时代内容优化的范式革命
大数据·人工智能·计算机网络
wdfk_prog3 小时前
[Linux]学习笔记系列 -- [fs]inode
linux·笔记·学习
AI视觉网奇3 小时前
ue 蓝图动画学习笔记
笔记·学习·ue5