用了Elasticsearch,一口气上5T
es_mapping

es_mapping

关于es映射mapping中的enabled,store,index参数的理解

Elasticsearchzz_hello 发表了文章 • 3 个评论 • 18665 次浏览 • 2018-11-28 16:08 • 来自相关话题

    因为刚才的一个问题,去看了一下es的文档中关于mapping参数的部分,发现了几个比较有意思的参数,index,store和enabled。下面简要说一下这几个参数的作用,有理解错和不足的地方希望大家指正。 enabled参数:     默认是true。只用于mapping中的object字段类型。当设置为false时,其作用是使es不去解析该字段,并且该字段不能被查询和store,只有在_source中才能看到(即查询结果中会显示的_source数据)。设置enabled为false,可以不设置字段类型,默认为object index参数:     默认是true。当设置为false,表明该字段不能被查询,如果查询会报错。但是可以被store。当该文档被查出来时,在_source中也会显示出该字段。 store参数:     默认false。store参数的功能和_source有一些相似。我们的数据默认都会在_source中存在。但我们也可以将数据store起来,不过大部分时候这个功能都很鸡肋。不过有一个例外,当我们使用copy_to参数时,copy_to的目标字段并不会在_source中存储,此时store就派上用场了。 三者能否同时存在:     首先设置了enabled为false就不能设置store为true了,这两者冲突。而index和store是不冲突的。最后index和enabled之间的问题:enabled需要字段类型为object,而当字段类型为object时,好像不能设置index参数,试了几次都会报错。
PUT mindex/
{
  "mappings": {
    "type": {
      "properties": {
        "name": {
          "type": "text",
          "copy_to": "name_title",
          "store": true,
          "index": false
        },
        "title": {
          "type": "text",
          "copy_to": "name_title"
        },
        "name_title": {
          "type": "text",
          "store": true
        },
        "notenabled": {
          "type": "object",
          "enabled": false
        }
      }
    }
  }
}
PUT mindex/type/1
{
  "name":"zz",
  "title":"zxx",
  "notenabled":"baby"
}
在搜索中使用了stored_fields之后,_source不会自己出现了,要手动指定字段。stored_fields里面不能出现notenabled。
GET /mindex/_search
{
  "query": {
    "match": {
      "title": "zxx"
    }
  },
  "stored_fields": ["name_title","title","name"],
  "_source": ["name_title","title","name","notenabled"]
}
结果
"_source": {
          "name": "zz",
          "title": "zxx",
          "notenabled": "baby"
        },
        "fields": {
          "name": [
            "zz"
          ],
          "name_title": [
            "zz",
            "zxx"
          ]
        }
看到结果,与上面的分析吻合。

关于es映射mapping中的enabled,store,index参数的理解

Elasticsearchzz_hello 发表了文章 • 3 个评论 • 18665 次浏览 • 2018-11-28 16:08 • 来自相关话题

    因为刚才的一个问题,去看了一下es的文档中关于mapping参数的部分,发现了几个比较有意思的参数,index,store和enabled。下面简要说一下这几个参数的作用,有理解错和不足的地方希望大家指正。 enabled参数:     默认是true。只用于mapping中的object字段类型。当设置为false时,其作用是使es不去解析该字段,并且该字段不能被查询和store,只有在_source中才能看到(即查询结果中会显示的_source数据)。设置enabled为false,可以不设置字段类型,默认为object index参数:     默认是true。当设置为false,表明该字段不能被查询,如果查询会报错。但是可以被store。当该文档被查出来时,在_source中也会显示出该字段。 store参数:     默认false。store参数的功能和_source有一些相似。我们的数据默认都会在_source中存在。但我们也可以将数据store起来,不过大部分时候这个功能都很鸡肋。不过有一个例外,当我们使用copy_to参数时,copy_to的目标字段并不会在_source中存储,此时store就派上用场了。 三者能否同时存在:     首先设置了enabled为false就不能设置store为true了,这两者冲突。而index和store是不冲突的。最后index和enabled之间的问题:enabled需要字段类型为object,而当字段类型为object时,好像不能设置index参数,试了几次都会报错。
PUT mindex/
{
  "mappings": {
    "type": {
      "properties": {
        "name": {
          "type": "text",
          "copy_to": "name_title",
          "store": true,
          "index": false
        },
        "title": {
          "type": "text",
          "copy_to": "name_title"
        },
        "name_title": {
          "type": "text",
          "store": true
        },
        "notenabled": {
          "type": "object",
          "enabled": false
        }
      }
    }
  }
}
PUT mindex/type/1
{
  "name":"zz",
  "title":"zxx",
  "notenabled":"baby"
}
在搜索中使用了stored_fields之后,_source不会自己出现了,要手动指定字段。stored_fields里面不能出现notenabled。
GET /mindex/_search
{
  "query": {
    "match": {
      "title": "zxx"
    }
  },
  "stored_fields": ["name_title","title","name"],
  "_source": ["name_title","title","name","notenabled"]
}
结果
"_source": {
          "name": "zz",
          "title": "zxx",
          "notenabled": "baby"
        },
        "fields": {
          "name": [
            "zz"
          ],
          "name_title": [
            "zz",
            "zxx"
          ]
        }
看到结果,与上面的分析吻合。