ElasticSearch的_all域

 ElasticSearch默认为每个被索引的文档都定义了一个特殊的域 - '_all',它自动包含被索引文档中一个或者多个域中的内容, 在进行搜索时,如果不指明要搜索的文档的域,ElasticSearch则会去搜索_all域。_all带来搜索方便,其代价是增加了系统在索引阶段对CPU和存储空间资源的开销。

       默认情况,ElasticSarch自动使用_all所有的文档的域都会被加到_all中进行索引。可以使用"_all" : {"enabled":false} 开关禁用它。如果某个域不希望被加到_all中,可以使用 "include_in_all":false。例如:

 

  1. {  
  2.    "person": {  
  3.       "_all": { "enabled": true }  
  4.       "properties": {  
  5.          "name": {  
  6.             "type": "object",  
  7.             "dynamic": false,  
  8.             "properties": {  
  9.                "first": {  
  10.                   "type": "string",  
  11.                   "store": true,  
  12.                   "include_in_all": false  
  13.                },  
  14.                "last": {  
  15.                   "type": "string",  
  16.                   "index": "not_analyzed"  
  17.                }  
  18.             }  
  19.          },  
  20.          "address": {  
  21.             "type": "object",  
  22.             "include_in_all": false,  
  23.             "properties": {  
  24.                "first": {  
  25.                   "properties": {  
  26.                      "location": {  
  27.                         "type": "string",  
  28.                         "store": true,  
  29.                         "index_name": "firstLocation"  
  30.                      }  
  31.                   }  
  32.                },  
  33.                "last": {  
  34.                   "properties": {  
  35.                      "location": {  
  36.                         "type": "string"  
  37.                      }  
  38.                   }  
  39.                }  
  40.             }  
  41.          },  
  42.          "simple1": {  
  43.             "type": "long",  
  44.             "include_in_all": true  
  45.          },  
  46.          "simple2": {  
  47.             "type": "long",  
  48.             "include_in_all": false  
  49.          }  
  50.       }  
  51.    }  
  52. }  


查询时,_all和其它域一样使用:

 

  1. GET /profiles/_search  
  2. {  
  3.     "query": {  
  4.         "match": {  
  5.            "_all": "food"  
  6.         }  
  7.     }  
  8. }  

 

或者在不提供搜索域的情况下,默认会搜索_all,例如:

  1. GET /profiles/_search  
  2. {  
  3.     "query": {  
  4.         "query_string": {  
  5.             "query": "food"  
  6.         }  
  7.     }  
  8. }  

 

参考资源

1. Lucene Scoring and elasticsearch's _all Field

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值