本文介绍了在ElasticSearch中只获取结果文档,不包括使用PHP库的其他元数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前的查询结果为

  {
take:13,
timed_out:false,
_shards:{
total:5,
success:5,
failed:0
}
hits:{
total:1,
max_score:1,
hits:[
{
_index :ABC,
_type:users,
_id:1,
_score:1,
fields $ bpartial1:{
uid:1,
pic:21398129082209.jpg,
utype:m,
用户:约翰·史密斯
}
}
}
]
}
}
pre>

每秒不同的1000个查询有超过100000次点击。



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

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

如果同时存在成千上万的请求,这是性能问题。并将结果文件发送给客户,因为他们键入的东西需要尽可能快。有没有出路?有一个关于SO的问题,但大概是一年左右,并且表示不屑一顾。或者我只需要做我正在做的事情。

解决方案

使用filter_path查询参数。它非常灵活。例如,为了仅包含所有结果的_source字段(从而排除响应中的所有其他元数据),请使用:?filter_path = hits.hits._source 。自从1.6以来它一直在其余的api。




My current result of a query is as

{
"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"
                }
            }
        }
    ]
}
}

There are more than 100000 hits returnd on different 1000 queries per second.

I want to exclude other Meta Data information from my result specially _index and type as I am using PHP Library to retrieve documents and send it to client. So, this expose my Index and type to clients which can be security issue. Currently I am looping through result like

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

This is performance issue if there are thousands of requests simuntaneously. And sending resulted documents to client as they type something needs to be faster as much as possible. Is there some way out? There is a question on SO but that is about a year old and says it is currenly not supported. Or I just have to do what I am doing?

解决方案

Use the "filter_path" query parameter. It's very flexible. For example, to only include the _source field for all results (and thereby exclude all the other metadata in the response) use: ?filter_path=hits.hits._source. Its been in the rest api since 1.6 I think.

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

这篇关于在ElasticSearch中只获取结果文档,不包括使用PHP库的其他元数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 01:50