1.字段不建索引:index:false
PUT /test
{
"mappings": {
"test": {
"properties": {
"name1": {
"type": "keyword",
"index": false
}
}
}
}
}
2.数据只索引不存储
2.1方案一(不推荐)
setting中的通用属性Store
该属性的取值可以为yes和no,用于指定字段的原始属性是否存入索引。默认值是no.意味着不能在结果中返回字段的原始值(即使没有存储原始值,也可以使用Soure字段返回原始值)。如果已经建立索引可以搜索该字段的内容。
ElasticSearch默认是存储整个文件的,如果要改变这种情形的话可以设置:“_source”:{"enable":"false"}
2.2方案二(推荐)
排除不存储字段:"excludes": [ "name4"]
PUT /test
{
"settings": {}
}
PUT /test/_mapping/test
{
"_source": {
"excludes": [ "name4"]
},
"properties": {
"name1": {
"type": "keyword"
, "index": true
},
"name2": {
"type": "keyword"
, "index": false
},
"name3": {
"type": "text"
},
"name4": {
"type": "text"
}
}
}
PUT /test/test/01
{
"name1":"Republican congresswoman under fire for hanging a transphobic sign outs",
"name2":"Republican congresswoman under fire for hanging a transphobic sign outs",
"name3":"Republican congresswoman under fire for hanging a transphobic sign outs",
"name4":"Republican congresswoman under fire for hanging a transphobic sign outs"
}
GET /test/_search
{
"query": {
"bool": {"must": [
{
"match": {
"name1": "Republican congresswoman under fire for hanging a transphobic sign outs"
}}
]}
}
}