ElasticSearch的_all域
ElasticSearch默认为每个被索引的文档都定义了一个特殊的域 - '_all',它自动包含被索引文档中一个或者多个域中的内容, 在进行搜索时,如果不指明要搜索的文档的域,ElasticSearch则会去搜索_all域。_all带来搜索方便,其代价是增加了系统在索引阶段对CPU和存储空间资源的开销。默认情况,ElasticSarch自动使用_all所有的文档的域都会被加到_all中进行索引。可以使用"_all" : {"enabled":false} 开关禁用它。如果某个域不希望被加到_all中,可以使用 "include_in_all":false。例如:
[*]{
[*] "person": {
[*] "_all": { "enabled": true }
[*] "properties": {
[*] "name": {
[*] "type": "object",
[*] "dynamic": false,
[*] "properties": {
[*] "first": {
[*] "type": "string",
[*] "store": true,
[*] "include_in_all": false
[*] },
[*] "last": {
[*] "type": "string",
[*] "index": "not_analyzed"
[*] }
[*] }
[*] },
[*] "address": {
[*] "type": "object",
[*] "include_in_all": false,
[*] "properties": {
[*] "first": {
[*] "properties": {
[*] "location": {
[*] "type": "string",
[*] "store": true,
[*] "index_name": "firstLocation"
[*] }
[*] }
[*] },
[*] "last": {
[*] "properties": {
[*] "location": {
[*] "type": "string"
[*] }
[*] }
[*] }
[*] }
[*] },
[*] "simple1": {
[*] "type": "long",
[*] "include_in_all": true
[*] },
[*] "simple2": {
[*] "type": "long",
[*] "include_in_all": false
[*] }
[*] }
[*] }
[*]}
查询时,_all和其它域一样使用:
[*]GET /profiles/_search
[*]{
[*] "query": {
[*] "match": {
[*] "_all": "food"
[*] }
[*] }
[*]}
或者在不提供搜索域的情况下,默认会搜索_all,例如:
[*]GET /profiles/_search
[*]{
[*] "query": {
[*] "query_string": {
[*] "query": "food"
[*] }
[*] }
[*]}
参考资源
1. Lucene Scoring and elasticsearch's _all Field
页:
[1]