I can not see the document in the result

I am using elasticsearch-PHP and new to it. I wrote two scripts, one is for indexing a document under a custom analyzer:

<?php
require_once 'init.php';

if (!empty($_POST)) {
    if (isset($_POST['title'], $_POST['body'], $_POST['keywords'])) {
        $title = $_POST['title'];
        $body = $_POST['body'];
        $keywords = explode(',', $_POST['keywords']);

        $index = [
            'index' => 'myindex2',
            'body' => [
                'settings' => [
                    'analysis' => [
                        'analyzer' => [
                            'my_analyzer' => [
                                "type" => "custom",
                                'tokenizer' => 'standard',
                                'filter' => [
                                    'lowercase',
                                    'asciifolding',
                                    'snowball',
                                    "language" => "english"
                                ]
                            ]
                        ]
                    ]
                ]
            ]
        ];
        $client->indices()->create($index);

        $params = [
            'index' => 'myindex2',
            'type' => 'article',
            'id' => '1',
            'body' => [
                'title' => $title,
                'body' => $body,
                'keywords' => $keywords
            ]
        ];

        $response = $client->index($params);

        if ($response) {
            print_r($response);
        }
    }
}

?>

And another script is for searching inside indexed documents:

<?php
require_once 'init.php';

if (isset($_GET['q'])) {
    $q = $_GET['q'];

    $params = [
        'index' => 'myindex2',
        'type' => 'article',
        'size' => 10,
        'body' => [
            "query" => [
                "bool" => [
                    "should" => [
                        [
                            "match_phrase" => [
                                "body" => [
                                    'query' => $q,
                                    'analyzer' => 'my_analyzer',
                                    'slop' => 3,
                                    "boost" => 8.0
                                ]
                            ]
                        ],
                        [
                            "match" => [
                                "body" => [
                                    'query' => $q,
                                    'analyzer' => 'my_analyzer',
                                    "boost" => 3.0
                                ]
                            ],
                        ]
                    ]
                ]
            ]
        ]
    ];
    $query = $client->search($params);
    echo '<pre>', print_r($query), '</pre>';
}
?>

As shown in the first script, I used "snowball" token filter in my custom analyzer (my_analyzer) and used that inside the search query in the second script. Assuming I index, for example, a document such as :

title: "test"
body: "The 2 QUICK Brown-Foxes jumped over the lazy dog's bone."
keywords : ""

when I search "the" or "over" or "bone", I see the above document in the result. but when I search "Foxes" or "fox" or "lazy" or "lazi", I do not see the above document in the result. May you please clarify me?
Thanks a lot

You need to define a mapping which uses my_analyzer at index time.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.