dongtang5776
2016-01-18 06:32
浏览 41
已采纳

elasticsearch php多个名字

I have FNAME and LNAME and Address that I want to search on. I want to search

FName = jo
LName = ro
Address = 34

that should give me all the records that have FName and LName starting with jo and ro (LIKE) so if it was mysql it would be FNmae Like jp% And LName Like ro% AND Address Like 34%

so I have so far this

 $params = [
            'index' => $this->arrayES['index'],
            'type' =>  $this->arrayES['type'],
            'body' => [
                'query' => [
                    'match' =>  ["FName"=>"Jo"]
                ]
            ]
        ];

Problem with that is that it gives me only JO

and when I try to add LName and Address

'match' =>  ["FName"=>"Jo", "LName"=>"ro", "Address"=>"34"]

that errors out.

Need some help

thanks

** Expected Results **

FName             LName             Address
Jo                  Ro               34 W Ave
John                Rosa             3456 Havana Ave
Johnny              Ronnatte         341 House Rd

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

我有要搜索的FNAME,LNAME和地址。 我想搜索

  FName = jo 
LName = ro 
Address = 34 
   
 
 

应该给我 具有FName和LName的所有记录以jo和ro(LIKE)开头 如果它是mysql它将是 FNmae像jp%和LName像ro%AND地址像34%

所以我到目前为止这个

  $ params = [
'index'=>  $ this-> arrayES ['index'],
'type'=>  $ this-> arrayES ['type'],
'body'=>  [
'查询'=>  [
'匹配'=>  [“FName”=>“Jo”] 
] 
] 
]; 
   
 
 

问题在于它只给我一个JO

当我尝试添加LName和地址

 'match'=>  [“FName”=>“Jo”,“LName”=>“ro”,“地址”=>“34”] 
   
 
 

错误 需要一些帮助

谢谢

**预期结果** \ n

  FName LName Address 
Jo Ro 34 W Ave 
John Rosa 3456 Havana Ave 
Johnny Ronnatte 341 House Rd 
   
 
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • donglian4770 2016-01-18 06:40
    已采纳

    There's a way which allows to specify a very similar query to your SQL query, using the query_string query:

     $params = [
            'index' => $this->arrayES['index'],
            'type' =>  $this->arrayES['type'],
            'body' => [
                'query' => [
                    'query_string' =>  [
                        'query' => 'FName:Jo* AND LName:ro* AND Address:34*'
                    ]
                ]
            ]
        ];
    
    点赞 打赏 评论

相关推荐 更多相似问题