欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 文旅 > 艺术 > ES——域的属性

ES——域的属性

2025/4/19 8:05:29 来源:https://blog.csdn.net/wusuoweiieq/article/details/144372447  浏览:    关键词:ES——域的属性

目录

  • index
  • type
  • store

指的是索引中文档属性或字段
在这里插入图片描述


index

描述:指定该域是否创建索引。只有设置为true时,才能根据该域的关键词查询文档。如果设置为false,则该域不会被索引,因此无法通过该域进行搜索。
示例

PUT /student1
{"mappings": {"properties": {"id": {"type": "integer","index": true}}}
}PUT /student2
{"mappings": {"properties": {"id": {"type": "integer","index": false}}}
}POST /student1/_doc/1
{"id":1
}
POST /student2/_doc/1
{"id":1
}GET /student1/_search
{"query": {"term": {"id": "1"}}
}GET /student2/_search
{"query": {"term": {"id": "1"}}
}

student1结果输出
正常查询

{"took" : 4,"timed_out" : false,"_shards" : {"total" : 1,"successful" : 1,"skipped" : 0,"failed" : 0},"hits" : {"total" : {"value" : 1,"relation" : "eq"},"max_score" : 1.0,"hits" : [{"_index" : "student1","_type" : "_doc","_id" : "1","_score" : 1.0,"_source" : {"id" : 1}}]}
}

student2结果输出
400报错,没建立倒排索引

{"error" : {"root_cause" : [{"type" : "query_shard_exception","reason" : "failed to create query: Cannot search on field [id] since it is not indexed.","index_uuid" : "lazrSPmCSAuyr-Bw4phQ3g","index" : "student2"}],"type" : "search_phase_execution_exception","reason" : "all shards failed","phase" : "query","grouped" : true,"failed_shards" : [{"shard" : 0,"index" : "student2","node" : "XwyTfyX-RQCee8Bm1dxbdQ","reason" : {"type" : "query_shard_exception","reason" : "failed to create query: Cannot search on field [id] since it is not indexed.","index_uuid" : "lazrSPmCSAuyr-Bw4phQ3g","index" : "student2","caused_by" : {"type" : "illegal_argument_exception","reason" : "Cannot search on field [id] since it is not indexed."}}}]},"status" : 400
}

type

描述:定义域的数据类型,决定了Elasticsearch如何存储和索引数据。

核心类型具体类型
字符串类型text
整数类型long, integer, short, byte
浮点类型double, float
日期类型date
布尔类型boolean
数组类型array (of any other datatype)
对象类型object (typically a JSON object)
不分词的字符串keyword

keyword示例
查询时必须输入一样的内容才可以正确查询,否则查不到(比如姓名,手机号等等不可分词的内容)

PUT /student2
{"mappings": {"properties": {"name": {"type": "keyword","index": true}}}
}
POST /student2/_doc/1
{"name":"I am wunaiieq"
}
GET /student2/_search
{"query": {"term": {"name": "I am wunaiieq"}}
}

store

描述:控制是否单独存储域的值。如果设置为true,则可以单独查询该域的值,而不需要通过_source字段获取整个文档。(一般使用在经常查询的列中)
简言:直接查询这个字段下所有的值
示例

PUT /student1
{"mappings": {"properties": {"name": {"type": "keyword","index": true,"store": true},"age":{"type": "integer"}}}
}
POST /student1/_doc/1
{"name":"I am wunaiieq01","age":101
}
GET /student1/_search
{"stored_fields": ["name"]
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词