ES查看分词结果|es字段类型修改|ES常用命令

查看分词结果
//query结构
GET /{index}/{type}/{_id}/_termvectors?fields={field_name}
//示例
GET /youdu_test/books/41286/_termvectors?fields=book_name
sort脚本排序
"sort": {
      "_script": {
        "type": "string",
        "script":{
          "inline": "doc['book_author']"
        },
        "order":"asc"
      }
  }
修改mapping中的字段类型

此处示例index为:youdu(已存在) youdu_test(为未创建)
以下请求的header都为:Content-Type:application/json

    1. 新建一个替代index(youdu_test)
    1. 获取youdu的mapping
//query结构
GET $domain+$port/{index}/{type}/_mapping
//示例
GET http://192.168.0.202:9200/youdu/books/_mapping

截取{type}部分json留做后面建立youdu_test的mapping使用,如

{
    "youdu": {
        "mappings": {
            "books": {
                "properties": {
                    "auto_gather": {
                        "type": "keyword"
                    },
                    
                }
            }
        }
    }
}
    1. 创建youdu_test的mapping
      将上面截取的{type}部分json去传入和修改
//query结构
PUT $domain+$port/{index}/{type}/_mapping
{
  //json串
}
//示例,更改auto_gather字段的类型为text
PUT http://192.168.0.202:9200/youdu_test/books/_mapping
{
    "books": {
                "properties": {
                    "auto_gather": {
                        "type": "text"
                    },
                  
                }
            }
}
    1. 同步youdu的数据到youdu_test
//query结构
POST $domain+$port/_reindex
//示例
POST http://192.168.0.202:9200/_reindex
{
 "source": {
     "index": "youdu"
 },
 "dest": {
     "index": "youdu_test"
 }
}
获取所有别名

GET _cat/aliases?v

获取_index_name模式内所有指定别名为_alias_name模式的index

GET /_index_name/_alias|_aliases/_alias_name
_alias和_aliases的区别为若指定为_aliases在查询时若_index未指定满足要求的别名在返回结果中是否包含但aliasese属性为空, 使用_alias时不包含该index

设置别名

PUT /_index_name/_alias/_alias_name

删除别名
DELETE /_index_name/_alias/_alias_name

持续更新 +1

为已有index/type添加字段并设置默认值
//1.先插入字段
PUT /{index}/_mapping/{type}
{
  "properties": {
    "m_part_limit":{
        "type": "long"
    }
  }
}

//然后设置默认值
POST /{index}/_update_by_query
{
  "script": {
    "lang": "painless",
    "inline": "if (ctx._source.m_part_limit== null) {ctx._source.m_part_limit= 15}"
  }
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容