0

I'm using elasticsearch version 8.4 with PHP. I created the index articles e and he has all the registers that are present in the correspondent table in database.

I need to do a search with elasticsearch that return the same results that a SQL search would do.

SELECT * 
FROM articles 
WHERE title LIKE '%Document%' 

However, the results are not the same using elasticsearch php. The php code follows:

<?php 
require_once "vendor/autoload.php";

use Elastic\Elasticsearch\ClientBuilder;

$client = ClientBuilder::create()
    ->setHosts(['localhost:9200'])
    ->setBasicAuthentication('elastic','secret')
    ->build();

$params = [
    'index' => 'articles',
    'from' => 0,
    'size' => 5000,
    'body'  => [
        'query' => [
            'match' => [
                'title' => 'Document'
            ]
        ]
    ]
];

if (!empty($results['hits']['hits']))
{
    echo "<pre>";
    print_r($results['hits']['hits']);
    echo "</pre>";
}

I tried 'wildcards' and 'regexp' instead of 'match', but it not worked.

I read these pages of docs to help in this case:

https://www.elastic.co/guide/en/elasticsearch/reference/current/sql-like-rlike-operators.html#sql-like-operator https://www.elastic.co/guide/en/elasticsearch/client/php-api/8.4/search_operations.html

Is there any to reproduce this elasticsearch php code return same results of sql query executed directly in database?

DiChrist
  • 351
  • 7
  • 18

0 Answers0