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"]
    }
  }
}
相关推荐
aramae1 分钟前
数据结构与算法(递归)
开发语言·经验分享·笔记·算法
程序员大雄学编程7 分钟前
「深度学习笔记1」深度学习全面解析:从基本概念到未来趋势
人工智能·笔记·深度学习
聪明的笨猪猪11 分钟前
Java 面试清单(含超通俗生活案例与深度理解)
java·经验分享·笔记·面试
数智顾问33 分钟前
破解 Shuffle 阻塞:Spark RDD 宽窄依赖在实时特征工程中的实战与未来
大数据·分布式·spark
骁的小小站39 分钟前
Learn C the Hardway学习笔记和拓展知识(一)
c语言·开发语言·c++·经验分享·笔记·学习·bash
Giser探索家1 小时前
遥感卫星升轨 / 降轨技术解析:对图像光照、对比度的影响及工程化应用
大数据·人工智能·算法·安全·计算机视觉·分类
摇滚侠1 小时前
Spring Boot 3零基础教程,yml语法细节,笔记16
java·spring boot·笔记
能不能别报错1 小时前
K8s学习笔记(二十) 亲和性、污点、容忍、驱逐
笔记·学习·kubernetes
lisw052 小时前
数字化科技简化移民流程的 5 种方式
大数据·人工智能·机器学习
海梨花2 小时前
【八股笔记】SSM
java·开发语言·笔记·后端·面试·框架