一些ES使用事项

来源:互联网 发布:excel怎么复制所有数据 编辑:程序博客网 时间:2024/06/05 15:37

  • Elasticsearch
    • x版本Elasticsearch的fileddata
    • 不分词操作
    • 查询空字符串的字段
    • 更新需要用Script
    • 常用命令
      • index相关

Elasticsearch

5.x版本Elasticsearch的fileddata

默认text类型的字段不可以进行aggregation

需要对mapping进行更新,操作如下

PUT my_index/_mapping/my_type{  "properties": {    "my_type": {       "type":     "text",      "fielddata": true    }  }}

不分词操作

ES默认都是对值进行分词的,在mapping中添加不需要分词的field,可以在terms查询时精确查找不分词的值

例如Index为tags,mapping为tag,对mapping添加部分此的field操作如下:

PUT tags/_mapping/tag{  "properties": {    "tag": {      "type": "text",      "fields": {        "keyword": {          "type": "string",          "index": "not_analyzed"        }      }    }  }}

对mapping进行更新官方文档

查询空字符串的字段

查询的body如下

{    "query" : {        "bool": {            "must_not":[                 { "term" : { "entity_id": "" } }            ]        }    }}

更新需要用Script

下面是JS代码示例

let body = {    "query": { "bool": {        "must": must,        "must_not": mustNot    }},    "script": {        "inline": "ctx._source.tag = params.tag",        "params": {            "tag": newTag        },        "lang":"painless"    },};result = yield esclient.updateByQuery({    index: INDEX_NAME,    body: body});

常用命令

index相关

查看所有index

curl http://ip:9200/_cat/indices?v

删除index

curl -XDELETE 'http://ip:9200/tags'
原创粉丝点击