Hello,World

_source/_all特性效果

Elasticsearch | 作者 liushui00001 | 发布于2017年05月05日 | | 阅读数:4036

我经过实际测试es5.2.2,发现_source/_all特性很好用:
1. _source可用通过配置includes、excludes获取应用需要的field
"_source": {
          "enabled": true,
          "includes": [
            "comId",
            "name",
            "userName",
            "equips.name",
            "equips.amount"
          ],
          "excludes": [
            "phone",
            "equips.code"
          ]
        },
2.设置enabled=false关闭_source功能,关闭后,查询结果只返回doc的ID,而不会返回_source
 "_source": {
          "enabled": false,
3._all、include_in_all结合使用,是用户可用通过_all分词查询多个字段,而不需要写多个查询条件
 "mappings": {
      "testdoc03": {
        "_all": {
          "enabled": true
        },
        "_source": {
          "enabled": false,
          "includes": [
            "comId",
            "name",
            "userName",
            "equips.name",
            "equips.amount"
          ],
          "excludes": [
            "phone",
            "equips.code"
          ]
        },
        "properties": {
          "comId": {
            "type": "long"
          },
          "equips": {
            "properties": {
              "amount": {
                "type": "double",
                "include_in_all": true
              },
              "code": {
                "type": "text"
              },
              "name": {
                "type": "text",
                "include_in_all": true
              }
            }
          },
          "name": {
            "type": "text",
            "include_in_all": true
          },
          "phone": {
            "type": "keyword"
          },
          "userName": {
            "type": "text",
            "include_in_all": true
          }
        }
      }
    }
  }
 

[尊重社区原创,转载请保留或注明出处]
本文地址:http://elasticsearch.cn/article/160


3 个评论

启用_all,在索引文档的时候性能会受到一定程度的影响吧
是的,会消耗更多内存,如果实际应用中能够容忍,是一个很好的选择;我的项目中就使用了_all;
一句话,根据自身的业务需求,要有取舍
你将需要被搜索的都放到 _all 中,那不是所有的字段都是一样的权重了!

要回复文章请先登录注册