douan3414
2017-11-27 17:26
浏览 153
已采纳

在弹性搜索格式错误的查询中按日期范围搜索

I am trying to integrate search by date range with PHP and elastic search

$params1 = [
'index' => 'joborders',
'type' => 'joborder',
'from' =>0,
'size' => 50,


     'body' => [

     'query' => [
            'query_string' => [
                'query' => $wildCardString,
                'fields' => ['description'],

                ]
        ]
    ]
];

$filter_date=array();
$filter_date['range']['datecreatedsort']['gte']='2015-11-27';
$filter_date['range']['datecreatedsort']['lte']='2017-11-27';
$params1['body']['query']['filtered']['filter']=$filter_date;
$params1['body']['sort']['datecreatedsort']['order'] = 'desc';

   try {
     $results = $client->search($params1);
     //print_r($results);
   }
   catch (Exception $e) {
$last = $client->transport->getLastConnection()->getLastRequestInfo();
$last['results']['error'] = [];
print_r($last);
}

When I am running above query I am getting following error

[query_string] malformed query, expected [END_OBJECT] but found [FIELD_NAME]","line":1,"col":78},"status":400}

datecreatedsort filed mapping is date type is date and value in elastic search db is "datecreatedsort":"2016-05-30T09:39:40.000Z"

please help where is the issue in elastic query.

图片转代码服务由CSDN问答提供 功能建议

我正在尝试将搜索按日期范围与PHP和弹性搜索集成

  $ params1 = [
'index'=>  'joborders',
'type'=>  'joborder',
'from'=> 0,
'size'=>  50,
 
 
'body'=>  [
 
'query'=>  [
'query_string'=>  [
'查询'=>  $ wildCardString,
'fields'=>  ['description'],
 
] 
] 
] 
]; 
 
 $ filter_date = array(); 
 $ filter_date ['range'] ['datecreatedsort'] ['gte'  ] = '2015年11月27日'; 
 $的filter_date [ '范围'] [ 'datecreatedsort'] [ 'LTE'] = '2017年11月27日'; 
 $的params1 [ '体'] ['查询 ''['过滤'] ['过滤器'] = $ filter_date; 
 $ params1 ['body'] ['sort'] ['datecreatedsort'] ['order'] ='desc'; 
 
尝试 {
 $ results = $ client-> search($ params1); 
 // print_r($ results); 
} 
 catch(Exception $ e){
 $ last = $ client-> transport  - > getLastConnection() - > getLastRequestInfo(); 
 $ last ['results'] ['error'] = []; 
print_r($ last); 
} 
   
 
 

当我在查询之上运行时,我收到以下错误

[query_string]格式错误的查询,预期[END_OBJECT]但找到了 [ FIELD_NAME]“,”line“:1,”col“:78},”status“:400}

datecreatedsort字段映射日期类型是 弹性搜索数据库中的日期和值 是“datecreatedsort”:“2016-05-30T09:39:40.000Z”

请帮助wher e是弹性查询中的问题。

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

3条回答 默认 最新

相关推荐 更多相似问题