空类型的Elasticsearch查询会出错并且不起作用吗?

时间:2016-06-22 04:57:48

标签: php laravel elasticsearch

假设我有一个类型' audit_ssn'并且没有任何doc,映射就像:

protected $audit_ssn_mapping_properties = array(
    'index' => 'my_index',
    'type' => 'audit_ssn',
    'body' => [
        'audit_ssn' => [
            '_source' => [
                'type' => 'string',
                'analyzer' => 'standard'
            ],
            'properties' => [
                'session_id' => array("type" =>  "string"),
                'user_id'    => array(
                    'type'      => 'nested',
                    'properties' => array(
                        'id'            => array('type' => 'string'),
                        'first_name'    => array('type' => 'string'),
                        'last_name'     => array('type' => 'string'),
                        "unique_user_id" => array("type" => "string")
                    )
                ),
                'date'         => array(
                    'type'   => 'date',
                    'format' =>'YYYY-MM-dd||YYYY-MM-dd||MM/dd/yyyy||yyyy/MM/dd'
                ),
                'time' => array(
                    'type'   => 'date',
                    'format' => 'HH:mm:ss'
                )
            ]
        ]
    ]
);

现在,当我想运行bellow查询问题时。

GET my_index/audit_ssn/_search
{
   "query":{
     "filtered":{
        "filter":{
            "and":[
                {
                    "nested":{
                        "path":"user_id",
                        "query":{
                            "terms":{
                                "user_id.id":["1000001"],
                                "minimum_match":1
                            }
                        }
                    }
                }
            ]
        }
     }
  }
}

,错误如下:

nested: QueryParsingException[[my_index] [nested] failed to find nested object under path [user_id]]; }{[y0tlRvUzQ8SyyHheSxcd2g][my_index][1]: SearchParseException[[my_index][1]: from[-1],size[-1]: Parse Failure

如何解决这个问题? 有没有办法检查类型是否为空,然后运行查询? 或者如何修改此查询以返回空结果?

0 个答案:

没有答案