1

i want to search with elasticsearch and show out the result with php. i want to make partial match like it's in mysql for ex:

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

But my codes doesn`t work:

$params = [
    'index' => 'my_index',
    'type' => 'my_type',
    'body' => [
        'query' => [
            'match' => [
                'title' => '.*abc.*'
            ]
        ]
    ]
];
2
  • you need to tokenize the fields in a different way. (something ngram filters ) check this link elastic.co/guide/en/elasticsearch/guide/current/… Commented Oct 5, 2017 at 23:11
  • post your index setting, mappings for more clarified answers Commented Oct 5, 2017 at 23:12

1 Answer 1

3

I was using 'match' instead of 'regex'

$params = [
    'index' => 'my_index',
    'type' => 'my_type',
    'body' => [
        'query' => [
            'regexp' => [
                'title' => '.*abc.*'
            ]
        ]
    ]
];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.