美文网首页
003 dynamicMapping 和mapping

003 dynamicMapping 和mapping

作者: zhu733756 | 来源:发表于2020-03-15 20:48 被阅读0次

#DynamicMapping

#dynamic true/false/strict 

#true:新增字段时,可被储存,可被搜索

#false:新增字段时,可被储存,不可被搜索

#strict:新增字段,直接报错

PUT dynamic_mapping_test/_doc/1

{"ffield":"123"}

PUT dynamic_mapping_test/_mapping

{

  "dynamic": false

}

PUT dynamic_mapping_test/_doc/2

{"xsz":"123"}

GET dynamic_mapping_test/_search

{

  "query": {

    "match": {

      "xsz": {

        "query": "123"

      }

    }

  }

}

# results:0

PUT dynamic_mapping_test/_mapping

{

  "dynamic":"strict"

}

PUT dynamic_mapping_test/_doc/3

{

  "xsxx":"qwew"

}

#error

DELETE dynamic_mapping_test

#自定义mapping

# 四个字段级别:

# docs/freqs/position/offset

# offset级别最高,会分别建立doc_id,词频,词所在位置,词的偏移位置;

# Text类型在position 级别;

# mappings属性中指定index为false表示不会建立倒排索引,指定index_option可定义字段级别。

# copy_to也就是移花接木,将想要查询的字段指定另一个字段去查询

PUT users

{

  "mappings": {

  "properties": {

      "firstName":{

      "type":"text"

    },

    "lastName":{

      "type":"text"

    },

    "fullName":{

      "type":"text"

    },

    "mobile":{

      "type":"text",

      "index":false

    }

  }

  }

}

PUT users/_doc/1

{

  "firstName":"li",

  "lastName":"lei",

  "fullName":"li lei",

  "mobile":"12323131"

}

PUT users/_doc/2

{

  "firstName":"han",

  "lastName":"meimei",

  "fullName":"han meimei",

  "mobile":"12323131"

}

POST users/_search

{

  "query": {

    "match": {

      "mobile": "12323131"

    }

  }

}

DELETE users

PUT users

{

  "mappings": {

    "properties": {

      "firstName": {

        "type": "text",

        "copy_to": "fullName"

      },

      "lastName": {

        "type": "text",

        "copy_to": "fullName"

      },

      "fullName": {

        "type": "text"

      },

      "mobile": {

        "type": "text",

        "index": false

      }

    }

  }

}

PUT users/_doc/1

{

  "firstName":"li",

  "lastName":"lei",

  "fullName":"li lei",

  "mobile":"12323131"

}

PUT users/_doc/2

{

  "firstName":"han",

  "lastName":"meimei",

  "fullName":"han meimei",

  "mobile":"12323131"

}

POST users/_search

{

  "query": {

    "match": {

      "lastName": {

        "query": "li meimei",

        "operator": "or"

      }

    }

  }

}

相关文章

网友评论

      本文标题:003 dynamicMapping 和mapping

      本文链接:https://www.haomeiwen.com/subject/hfpbehtx.html