Elasticsearch 中的根对象就是某个 doc 对应的 mapping json,包括了 properties,metadata(_id,_source,_type),settings(analyzer),其他 settings(比如 include_in_all)等。
type,index,analyzer PUT /indexname/_mapping { "properties": { "title": { "type": "text" } } }
查询的时候,直接可以拿到完整的 document,不需要先拿 document id,再发送一次请求拿 document。
partial update 基于 _source 实现。
reindex 时,直接基于 _source 实现,不需要从数据库(或者其他外部存储)查询数据再修改。
可以基于 _source 定制返回 field。
debug query 更容易,因为可以直接看到 _source。
如果不需要上述好处,可以禁用 _source,使用如下代码:
PUT /indexname/_mapping { "_source": {"enabled": false} }
将所有 field 打包在一起,作为一个 _all field,建立索引。没指定任何 field 进行搜索时,就是使用 _all field 在搜索。
PUT /my_index/_mapping { "_all": {"enabled": false} }
也可以在 field 级别设置 include_in_all field,设置是否要将 field 的值包含在 _all field 中:
PUT /my_index/_mapping { "properties": { "my_field": { "type": "text", "include_in_all": false } } }
_index,_type,_id
Elasticsearch 中的根对象就是某个 doc 对应的 mapping json,包括了 properties,metadata(_id,_source,_type),settings(analyzer),其他 settings(比如 include_in_all)等。