elasticsearch - Does anyone know about the query result highlighting problem of es-php or mmanos/laravel-search?

WBOY
Release: 2016-08-04 09:21:42
Original
1447 people have browsed it

The following code is implemented by laravel+elastisearch-php (https://github.com/elastic/elasticsearch-php), but it cannot return the highlighted content. I read it online at https://segmentfault.com/a/1190000003010186 and below. One example mentioned highlighting, but mmanos is not very good at using it. For example, how to find a query of a specified type under a specified index?
I’m not confused about the above method. Can any friend give me some advice? Thanks! ! !

<code>        $params=[
            'index' => 'n_index',
            'type' => 'n_type',
            'body' => [
                'query' => [
                    'match' => ['ntitle' => '要查询的词']
                ],
                'highlight'=>[
                    'pre_tags'=>['<tag1>', '<tag2>'],
                    'post_tags'=>['</tag1>', '</tag2>'],
                    'fields'=>[
                        'ntitle'=>[]
                    ]
                ]
            ]
        ];

        $response = $this->client->search($params);
    
        echo "<pre class="brush:php;toolbar:false">";
        var_dump($response);
        echo "
";
Copy after login
Copy after login

The above code can find the following results

<code>array(4) {
  ["took"]=>
  int(6)
  ["timed_out"]=>
  bool(false)
  ["_shards"]=>
  array(3) {
    ["total"]=>
    int(5)
    ["successful"]=>
    int(5)
    ["failed"]=>
    int(0)
  }
  ["hits"]=>
  array(3) {
    ["total"]=>
    int(3)
    ["max_score"]=>
    float(1.8223838)
    ["hits"]=>
    array(3) {
      [0]=>
      array(5) {
        ["_index"]=>
        string(7) "n_index"
        ["_type"]=>
        string(6) "n_type"
        ["_id"]=>
        string(1) "6"
        ["_score"]=>
        float(1.8223838)
        ["_source"]=>
        array(1) {
          ["ntitle"]=>
          string(35) "ntitle内容2"
        }
      }
      [1]=>
      array(5) {
        ["_index"]=>
        string(7) "n_index"
        ["_type"]=>
        string(6) "n_type"
        ["_id"]=>
        string(1) "7"
        ["_score"]=>
        float(1.2087858)
        ["_source"]=>
        array(1) {
          ["ntitle"]=>
          string(35) "ntitle内容1"
        }
      }
      [2]=>
      array(5) {
        ["_index"]=>
        string(7) "n_index"
        ["_type"]=>
        string(6) "n_type"
        ["_id"]=>
        string(1) "5"
        ["_score"]=>
        float(0.23033649)
        ["_source"]=>
        array(1) {
          ["ntitle"]=>
          string(35) "ntitle内容3"
        }
      }
    }
  }
}</code>
Copy after login
Copy after login

Highlights are not returned,

Reply content:

The following code is implemented by laravel+elastisearch-php (https://github.com/elastic/elasticsearch-php), but it cannot return the highlighted content. I read it online at https://segmentfault.com/a/1190000003010186 and below. One example mentioned highlighting, but mmanos is not very good at using it. For example, how to find a query of a specified type under a specified index?
I’m not confused about the above methods. Can anyone give me some advice? Thanks! ! !

<code>        $params=[
            'index' => 'n_index',
            'type' => 'n_type',
            'body' => [
                'query' => [
                    'match' => ['ntitle' => '要查询的词']
                ],
                'highlight'=>[
                    'pre_tags'=>['<tag1>', '<tag2>'],
                    'post_tags'=>['</tag1>', '</tag2>'],
                    'fields'=>[
                        'ntitle'=>[]
                    ]
                ]
            ]
        ];

        $response = $this->client->search($params);
    
        echo "<pre class="brush:php;toolbar:false">";
        var_dump($response);
        echo "
";
Copy after login
Copy after login

The above code can find the following results

<code>array(4) {
  ["took"]=>
  int(6)
  ["timed_out"]=>
  bool(false)
  ["_shards"]=>
  array(3) {
    ["total"]=>
    int(5)
    ["successful"]=>
    int(5)
    ["failed"]=>
    int(0)
  }
  ["hits"]=>
  array(3) {
    ["total"]=>
    int(3)
    ["max_score"]=>
    float(1.8223838)
    ["hits"]=>
    array(3) {
      [0]=>
      array(5) {
        ["_index"]=>
        string(7) "n_index"
        ["_type"]=>
        string(6) "n_type"
        ["_id"]=>
        string(1) "6"
        ["_score"]=>
        float(1.8223838)
        ["_source"]=>
        array(1) {
          ["ntitle"]=>
          string(35) "ntitle内容2"
        }
      }
      [1]=>
      array(5) {
        ["_index"]=>
        string(7) "n_index"
        ["_type"]=>
        string(6) "n_type"
        ["_id"]=>
        string(1) "7"
        ["_score"]=>
        float(1.2087858)
        ["_source"]=>
        array(1) {
          ["ntitle"]=>
          string(35) "ntitle内容1"
        }
      }
      [2]=>
      array(5) {
        ["_index"]=>
        string(7) "n_index"
        ["_type"]=>
        string(6) "n_type"
        ["_id"]=>
        string(1) "5"
        ["_score"]=>
        float(0.23033649)
        ["_source"]=>
        array(1) {
          ["ntitle"]=>
          string(35) "ntitle内容3"
        }
      }
    }
  }
}</code>
Copy after login
Copy after login

Highlights are not returned,

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template