原文链接 : https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-source-filtering.html

    译文链接 : http://www.apache.wiki/pages/editpage.action?pageId=4883082

    贡献者 : ping

    允许控制 _source 字段如何在每次命中返回。

    默认操作返回 _source 字段的内容,除非您已使用 stored_fields 参数或禁用 _source 字段。

    您可以使用 _source 参数关闭 _source 检索:

    要禁用 _source 检索设置为 false:

    1. GET /_search
    2. {
    3. "_source": false,
    4. "query" : {
    5. "term" : { "user" : "kimchy" }
    6. }
    7. }

    _source 还接受一个或多个通配符模式来控制 _source 的哪些部分应该返回:

    例如:

    GET /_search
    {
        "_source": "obj.*",
        "query" : {
            "term" : { "user" : "kimchy" }
        }
    }
    

    或者

    GET /_search
    {
        "_source": [ "obj1.*", "obj2.*" ],
        "query" : {
            "term" : { "user" : "kimchy" }
        }
    }
    

    最后,为了完全控制,您可以指定包含和排除模式:

    GET /_search
    {
        "_source": {
            "includes": [ "obj1.*", "obj2.*" ],
            "excludes": [ "*.description" ]
        },
        "query" : {
            "term" : { "user" : "kimchy" }
        }
    }