栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

elasticsearch 磁盘优化-index

elasticsearch 磁盘优化-index

 index参数 的作用

当我们不需要一些字段参数搜索和过滤时可以配置index来减轻我们的磁盘空间的消耗。

index 的默认值是true,是能够被索引和过滤的。

index = false 配置那些不需要搜索和过滤,只需要存储展示的字段情况

举个栗子: 创建索引
PUT whl_test
{
  "mappings": {
    "properties": {
      "age": {
        "type": "integer",
        "index": false
      },
      "name": {
        "type": "text",
        "norms": false
      },
      "address": {
        "type": "text",
        "index_options": "freqs"
      }
    }
  }
}
新增数据
PUT whl_test/_doc/1
{
  "age":1,
  "name":"张三",
  "address":"上海浦东"
}

此映射中的age的index被设置了false,这时他就不能被搜索和过滤,我看看效果。

查询语句
GET whl_test/_search
{
  "query": {
    "term": {
      "age": {
        "value": "1"
      }
    }
  }
}

GET whl_test/_search
{
  "query": {
    "match": {
      "age": "1"
    }
  }
}
报错信息
{
  "error" : {
    "root_cause" : [
      {
        "type" : "query_shard_exception",
        "reason" : "failed to create query: Cannot search on field [age] since it is not indexed.",
        "index_uuid" : "qeW607yzSBm3yI1q8DYpVw",
        "index" : "whl_test"
      }
    ],
    "type" : "search_phase_execution_exception",
    "reason" : "all shards failed",
    "phase" : "query",
    "grouped" : true,
    "failed_shards" : [
      {
        "shard" : 0,
        "index" : "whl_test",
        "node" : "v0LdTk8GS9ejsZ9k4kWJ8A",
        "reason" : {
          "type" : "query_shard_exception",
          "reason" : "failed to create query: Cannot search on field [age] since it is not indexed.",
          "index_uuid" : "qeW607yzSBm3yI1q8DYpVw",
          "index" : "whl_test",
          "caused_by" : {
            "type" : "illegal_argument_exception",
            "reason" : "Cannot search on field [age] since it is not indexed."
          }
        }
      }
    ]
  },
  "status" : 400
}

此时age是不能参数搜索和过滤的,但是他可以被返回。

查看索引数据:

GET whl_test/_search
{
  "query": {
   "match_all": {}
  }
}

数据:

{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "whl_test",
        "_type" : "_doc",
        "_id" : "1",
        "_score" : 1.0,
        "_source" : {
          "age" : 1,
          "name" : "张三",
          "address" : "上海浦东"
        }
      }
    ]
  }
}

可以看到_source中包含age的信息的。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/354613.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号