elasticsearch mapping index 说明

索引index 
这个参数可以控制字段应该怎样建索引,怎样查询。它有以下三个可用值: 
· no: 不把此字段添加到索引中,也就是不建索引,此字段不可查询 
· not_analyzed:将字段的原始值放入索引中,作为一个独立的term,它是除string字段以外的所有字段的默认值。 
· analyzed:string字段的默认值,会先进行分析后,再把分析的term结果存入索引中。

那么如果不需要的值,直接在mapping中设置为no就可以了。其它信息参考:store 和 _source field

简要说明:store就是把这个字段单独存储,默认是不存储的,默认存储的是 _source ,只有设置了才会存储,比如,有一个mapping有三个字段,title,subject,content,其中title,subject比较小,而content非常非常大,如果,你的查询结果只需要title,subject而不需要content时,把title,subject单独存储,可以节省很多时间

{
  "mappings": {
    "index": {
      "_all": {
        "enabled": false
      },
      "properties": {
        "ip": {
          "type": "string",
          "store":true
        }
      }
    }
  }
}

查询语句:

{
  "query": {
    "match": {
      "ip": "192.168.1.53"
    }
  }
}

结果:

{

  • "took"6,
  • "timed_out"false,
  • "_shards": {
    • "total"5,
    • "successful"5,
    • "failed"0
    },
  • "hits": {
    • "total"1,
    • "max_score"0.30685282,
    • "hits": [
      • {
        • "_index""test2",
        • "_type""domain_index",
        • "_id""1",
        • "_score"0.30685282,
        • "_source": {
          • "ip""192.168.1.53"
          }
        }
      ]
    }
}


index:no

{
  "mappings": {
    "index": {
      "_all": {
        "enabled": false
      },
      "properties": {
        "ip": {
          "type": "string",

"index":"no",

          "store":true
        }
      }
    }
  }
}

查询语句:

{
  "query": {
    "match": {
      "ip": "192.168.1.53"
    }
  }
}

结果:

{
  • "took"5,
  • "timed_out"false,
  • "_shards": {
    • "total"5,
    • "successful"5,
    • "failed"0
    },
  • "hits": {
    • "total"0,
    • "max_score"null,
    • "hits": [ ]
    }
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值