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"]
    }
  }
}
相关推荐
J-JunLiang12 分钟前
Flink 实时开发:关键知识点
大数据·flink
CodeCraft Studio40 分钟前
PPT处理控件Aspose.Slides教程:使用Java将PowerPoint笔记导出为PDF
java·笔记·pdf·powerpoint·aspose·ppt转pdf·java将ppt导出pdf
liliangcsdn1 小时前
如何使用elasticdump进行elasticsearch数据还原
大数据·elasticsearch·搜索引擎
仰望—星空1 小时前
MiniEngine学习笔记 : DescriptorHeap
windows·笔记·学习
yumgpkpm2 小时前
Doris 并入CMP7(类Cloudera CDP 7.3.1 404华为鲲鹏ARM版)的方案和实施源代码
大数据·oracle·sqlite·sqoop·milvus·cloudera
yumgpkpm2 小时前
Doris在CMP7(类Cloudera CDP 7 404版华为Kunpeng)启用 Kerberos部署Doris
大数据·hive·hadoop·python·oracle·flink·cloudera
YangYang9YangYan2 小时前
高职大数据技术专业学习与发展指南
大数据·人工智能·学习·数据分析
汤姆yu2 小时前
基于大数据的天气分析与应用系统
大数据
go_bai2 小时前
Linux--进程池
linux·c++·经验分享·笔记·学习方法
QT 小鲜肉3 小时前
【QT/C++】Qt网络编程进阶:UDP通信和HTTP请求的基本原理和实际应用(超详细)
c语言·网络·c++·笔记·qt·http·udp