【问题标题】:get only result documents in ElasticSearch excluding other meta data with PHP Library使用 PHP 库仅获取 ElasticSearch 中的结果文档,不包括其他元数据
【发布时间】:2016-02-16 04:27:40
【问题描述】:

我当前的查询结果为

{
"took": 13,
"timed_out": false,
"_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
},
"hits": {
    "total": 1,
    "max_score": 1,
    "hits": [
        {
            "_index": "ABC",
            "_type": "users",
            "_id": "1",
            "_score": 1,
            "fields": {
                "partial1": {
                    "uid": "1",
                    "pic": "21398129082209.jpg",
                    "utype": "m",
                    "user": "John Smith"
                }
            }
        }
    ]
}
}

每秒在不同的 1000 次查询中返回超过 100000 次点击。

我想从我的结果中排除其他元数据信息,特别是 _indextype,因为我正在使用 PHP 库检索文档并将其发送给客户端。因此,这会将我的 Indextype 暴露给客户,这可能是安全问题。目前我正在循环遍历结果,例如

 $ttl = count($results['hits']['hits']);
 $lst = array();
 for($i=0; $i<$ttl; $i++)
 {
  $lst[] = $results['hits']['hits'][$i]["fields"]["partial1"];
 }

如果同时有数千个请求,这就是性能问题。并且在客户键入内容时将结果文档发送给客户需要尽可能快。有什么出路吗?有一个关于 SO 的问题,但大约有一年的历史,并表示目前不支持。还是我只需要做我正在做的事?

【问题讨论】:

  • 没有办法直接在 ES 中执行此操作。你需要做你已经在做的事情。
  • 您对此有 100% 的把握吗? :(
  • WOW @DrTech Clinton 我刚刚访问了您的个人资料,看到您在 ElasticSearch.com 工作。太好了,我得到了 100% 的回答。
  • @DrTech 嗨,已经一年多了,有很多问题/请求能够在不牺牲性能的情况下过滤掉元数据。这仍然是100%不可能吗? Tnx :)

标签: json elasticsearch


【解决方案1】:

使用“filter_path”查询参数。它非常灵活。例如,要仅包含所有结果的 _source 字段(从而排除响应中的所有其他元数据),请使用:?filter_path=hits.hits._source。我认为它从 1.6 开始就在其余的 api 中。

https://www.elastic.co/guide/en/elasticsearch/reference/2.x/common-options.html#_response_filtering

【讨论】:

    猜你喜欢
    • 2020-01-19
    • 2014-07-27
    • 2017-08-08
    • 2020-01-03
    • 1970-01-01
    • 2020-11-05
    • 2011-03-20
    • 2022-07-05
    • 2011-11-20
    相关资源
    最近更新 更多