弹性搜索(PHP)多范围过滤器问题 [英] Elasticsearch (PHP) multiple range filters issue

查看:131
本文介绍了弹性搜索(PHP)多范围过滤器问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很喜欢Elasticsearch,所以道歉,如果这是一个明显的问题!



我正在使用PHP库,并试图做一个非常简单的查询一个索引。我唯一想做的就是在创建映射时对两个日期(visible_from和visible_to)执行一个过滤器,我已经设置了日期类型。



我正在建立代码中过滤的查询最终如下所示:

  array(
'index'=> 'site',
'from'=> 0,
'size'=> 10,
'body'=>
数组(
'查询'=>
array(
'filtered'=>
array(
'filter'=>
array(
'and'= >
数组(
'range'=>
数组(
'visible_from'=>
数组(
'lt'=> '2014-06-09 09:06:47',
),
'visible_to'=>
数组(
'gt'=>'2014-06- 09 09:06:47',
),
),
),
),
'query'=>
数组(
'match'=>
数组(
'_all'=>'example',
),
),




这导致了一个BadRequest400Exception被抛出 - 在异常的内容中,我可以看到Elasticsearch正在说

  QueryParsingException [[site] [和]过滤器不支持[]] 

如果我删除AND过滤器,只是执行范围过滤器对其中一个日期,那么它的工作原理完美,我只是无法让它使用AND过滤器



提前感谢任何帮助!

解决方案

尝试使用以下查询,尝试使用不同于或大于日期的不同。

  array 

query=>数组

filtered=> array

query=>数组

match=>数组(
'_all'=> 'example',
),
),

filter=>数组

和=>数组

filters=> array

0=> array

range=> array

ID=>数组

gt=>'2014-06-09 09:06:47',
),
) ,
),
1=>数组

range=>数组

ID=>数组

lt=>'2014-06-09 09:06:47',
) ,
),
),
),
),
),
),
),


I am pretty new to Elasticsearch, so apologies if this is is an obvious question!

I am using the PHP library and trying to do a pretty straightforward query across an index. The only thing I wanted to do was perform a filter against two dates (visible_from and visible_to) which I have set to date types when creating the mapping.

I am building up a filtered query in the code, which ends up looking like this:

array (
  'index' => 'site',
  'from' => 0,
  'size' => 10,
  'body' => 
  array (
    'query' => 
    array (
      'filtered' => 
      array (
        'filter' => 
        array (
          'and' => 
          array (
            'range' => 
            array (
              'visible_from' => 
              array (
                'lt' => '2014-06-09 09:06:47',
              ),
              'visible_to' => 
              array (
                'gt' => '2014-06-09 09:06:47',
              ),
            ),
          ),
        ),
        'query' => 
        array (
          'match' => 
          array (
            '_all' => 'example',
          ),
        ),
      ),
    ),
  ),
)

This results in a BadRequest400Exception being thrown - in the content of the exception I can see that Elasticssearch is saying

QueryParsingException[[site] [and] filter does not support [lt]]

If I remove the AND filter and just perform the range filter against one of the dates, then it works perfectly, I am just unable to get it working with the AND filter

Thanks in advance for any help!

解决方案

Make a try with below query, Try with different less than and greater than date.

array
(
    "query" => array
    (
    "filtered" => array
    (
        "query" => array
        (
            "match" => array(
                 '_all' => 'example',
                ),
             ),

            "filter" => array
            (
                "and" => array
                (
                    "filters" => array
                    (
                        "0" => array
                        (
                            "range" => array
                            (
                                "ID" => array
                                (
                                "gt" => '2014-06-09 09:06:47',
                                ),
                            ),
                        ),
                        "1" => array
                        (
                            "range" => array
                            (
                                "ID" => array
                                (
                                    "lt" => '2014-06-09 09:06:47',
                                ),
                            ),
                        ),
                    ),
                ),
            ),
        ),
    ),
)   

这篇关于弹性搜索(PHP)多范围过滤器问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆