首页 > 其他分享 >elastic-search HTTP请求

elastic-search HTTP请求

时间:2022-12-02 14:13:41浏览次数:38  
标签:index search HTTP name elastic GET 索引 range id

elastic-search请求

索引

  • 查看所有索引
GET _cat/indices?v&pretty
  • 查看索引信息
GET index_name/_mapping
  • 插入索引
PUT index_name
{
    "settings":{
   "number_of_shards":1,
        "number_of_replicas": 0
    },
    "mappings":{
        "properties":{
            "field_name":{
                "type":"field_type"
            },
            "range_field":{
                "type":"date_range",
                "format":"yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
            }
            ......
        }
    }
}
类型 特性 结构 场景
text 支持分词,全文检索,支持模糊、精确查询,不支持聚合,排序操作 最大支持的字符长度无限制,适合大字段存储 存储全文搜索数据, 例如: 邮箱内容、地址、代码块、博客文章内容等。默认结合standard analyzer(标准解析器)对文本进行分词、倒排索引。默认结合标准分析器进行词命中、词频相关度打分。
keyword 不进行分词,直接索引,支持模糊、支持精确匹配,支持聚合、排序操作。 keyword类型的最大支持的长度为——32766个UTF-8类型的字符,可以通过设置ignore_above指定自持字符长度,超过给定长度后的数据将不被索引,无法通过term精确匹配检索返回结果。 存储邮箱号码、url、name、title,手机号码、主机名、状态码、邮政编码、标签、年龄、性别等数据。    用于筛选数据(例如: select * from x where status='open')、排序、聚合(统计)。    直接将完整的文本保存到倒排索引中。
long、integer、short、byte、double、float、half_fliat、scaled_float 数字
date、data_nanos 日期
boolean 布尔型
binary 二进制类型 该字段默认情况下不存储,并且不可搜索。 该binary类型接受二进制值作为 Base64编码的字符串
integer_range、float_range、long_range、double_range、date_range 范围类型 用于查询存储区间
nested 内联
  • 删除索引
DELETE index_name
DELETE index_name1,index_name2
DELETE index_*
DELETE _all
  • 修改索引
PUT index_name/settings
{
    "number_of_replicas":1
}

数据

  • 查询全部
GET index_name/_search
{
  "size": 120,
  "query": {
    "match_all": {}
  }
}
  • 带条件查询
GET index_name/_search
{
  "query": {
    "term": {
      "id": "1598150740876988418"
    }
  }
}
  • 带条件查询-in
GET index_name/_search
{
  "query": {
    "terms": {
      "id": ["1598150740876988418"]
    }
  }
}
  • 插入数据
POST index_name/product
{
    "field1":"",
    "field2":"2022-12-12",
    ......
}
  • 带条件删除
GET index_name/_delete_by_query?pretty
{
  "query": {
    "term": {
      "id": "1598150740876988418"
    }
  }
}
  • 带条件删除-in
GET index_name/_delete_by_query?pretty
{
  "query": {
    "terms": {
      "id": ["1598150740876988418"]
    }
  }
}
  • 修改
POST index_name/_update/{id}?refresh=true
{
    "doc":{
        "field":"value"
    }
}
  • 覆盖式更新
PUT index_name/_doc/{id}?refresh=true
{
    "id": 1,
    .....
}
  • 修改不存在数据时,插入
POST index_name/_update/{id}?refresh=true
{
    "doc":{
        "field":"value"
    },
    "doc_as_upset":true
}

或者

POST index_name/_update/{id}?refresh=true
{
    "script":{
        "source": "ctx._source.field_name='field_value'"
    }
}

标签:index,search,HTTP,name,elastic,GET,索引,range,id
From: https://www.cnblogs.com/lhns/p/16944277.html

相关文章

  • 如何解决arthas-failed-to-bind-telnet-or-http-port问题
    解决方法一台机器启用多个微服务的时候可能出现多个arthas端口冲突。可以配置为随机端口,或者配置为-112#arthas.telnet-port=-1#arthas.http-port=-1并且通过tunnels......
  • ElasticSearch
    `ElasticSearch1.什么是ElasticSearchElasticSearch简称ES,是基于ApacheLucene构建的开源搜索引擎,是当前流行的企业级搜索引擎(分布式搜索引擎)。Lucene本身就可以......
  • 使用HTTPCLIENT去生成静态HTML页面
    一般生成HTML页时,都会用比如freemarker等去搞,但今天看到和学到一个还应该不错的方法,是使用httpclient的get方法,去读某个动态的URL,然后把读出的内容再......
  • 第六十四章 CSP的常见问题 - 发送给浏览器的HTTP头信息是什么
    第六十四章CSP的常见问题我想使用<csp:search>标记,但是我想允许用户搜索ID以外的字段。我可以这样做吗?<csp:search>标记有一个where属性,该属性允许指定要搜索的字段的......
  • 使用Fastjson作为http消息转换器
    主要是创建 FastJsonHttpMessageConverter的实例。@BeanpublicHttpMessageConvertersfastJsonHttpMessageConverters(){//1、定义一个convert转换消......
  • 98. Validate Binary Search Tree
    Givenabinarytree,determineifitisavalidbinarysearchtree(BST).AssumeaBSTisdefinedasfollows:Theleftsubtreeofanodecontainsonlynodeswit......
  • 79. Word Search
    Givena2Dboardandaword,findifthewordexistsinthegrid.Thewordcanbeconstructedfromlettersofsequentiallyadjacentcell,where"adjacent"cell......
  • Remove Node in Binary Search Tree
    GivenarootofBinarySearchTreewithuniquevalueforeachnode.Removethenodewithgivenvalue.Ifthereisnosuchanodewithgivenvalueinthebinary......
  • ElasticSearch笔记
    原文地址:https://www.kuangstudy.com/bbs/1354069127022583809笔记记录B站狂神说Java的ElasticSearch课程:https://www.bilibili.com/video/BV17a4y1x7zq在学习E......
  • Elasticsearch Mapping字段未支持索引导致搜索失效问题处理
    问题描述:生产上Es根据一个时间字段搜索,却没有返回数据问题分析:根据命令:GETindexName/_mapping查看#GETindexName/_mapping{ "indexName":{ "mappin......