Skip to content

Instantly share code, notes, and snippets.

@firecentaur
Created January 24, 2017 09:10
Show Gist options
  • Save firecentaur/38b89e338ca677f5f28105d87d60cbf2 to your computer and use it in GitHub Desktop.
Save firecentaur/38b89e338ca677f5f28105d87d60cbf2 to your computer and use it in GitHub Desktop.
<?php
require 'vendor/autoload.php';
use Elasticsearch;
use Elasticsearch\ClientBuilder;
use Elasticsearch\Connections\Connection;
$client = Elasticsearch\ClientBuilder::create()->setHosts(['http://ec2-35-154-104-170.ap-south-1.compute.amazonaws.com:9200'])->build();
$highlight = array(
"pre_tags" => array('<b>'),
"post_tags" => array('</b>'),
'fields' => array('cliptexts.content' => new \stdClass()),
"number_of_fragments" => 0
);
$page = 2;
$params = [
'index' => 'my_index2',
'type' => 'my_type2',
'body' => [
'query' => [
'nested' => [
'path' => 'cliptexts',
'query' => [
'match' => [
'cliptexts.content' => 'eat'
],
],
'inner_hits' => [
'highlight' => $highlight
]
],
],
'filter' => [
'term' => ['uid' => 29]
],
'from' => ($page - 1) * 10,
'size' => 2
]
];
# $params['body']['highlight'] = $highlight;
$results = $client->search($params);
header('Content-Type: application/json');
echo json_encode($results);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment