PHP elasticsearch部分匹配

时间:2017-10-05 18:53:31

标签: php mysql elasticsearch

我想用elasticsearch搜索并用php显示结果。我想在mysql中为它做部分匹配,例如:

select * from table_name where title like '%abc%'

但我的代码不起作用:

$params = [
    'index' => 'my_index',
    'type' => 'my_type',
    'body' => [
        'query' => [
            'match' => [
                'title' => '.*abc.*'
            ]
        ]
    ]
];

1 个答案:

答案 0 :(得分:0)

我使用'匹配'代替'正则表达式'

$params = [
    'index' => 'my_index',
    'type' => 'my_type',
    'body' => [
        'query' => [
            'regexp' => [
                'title' => '.*abc.*'
            ]
        ]
    ]
];