-1

thanks for helping me before, so now i can explore more about elastic search.

so far, i can manipulate data using elasticsearch. i create new library in my php framework (codeigniter). after make several data input. since the best part of elastic is searching (yeah of course....), i wonder to make search feature.

but when i create it, im dissapointed with the result. unlike kibana, my result didnt show the highlight text of keywords that i input before.

enter image description here

enter image description here

question is : how to make highlight text in elastic search result

i read this article : https://www.elastic.co/guide/en/elasticsearch/reference/2.3/search-request-highlighting.html

but i dont know where to put this code :

{
    "query" : {...},
    "highlight" : {
        "fields" : {
            **"content" : {}**
        }
    }
}

since my code in php only like this : controller :

$product = $this->elasticsearch->searchDocsWithParameter($type, $post);
$result = json_decode(json_encode($product),true);
echo "total took:";
echo $result['took'];    

$x=0; $no=1;
while($x <= $result['_shards']['total']):
echo $no; echo" . ";
echo $result["hits"]["hits"][$x]['_source']['en_question']; 
echo"<br>";
echo $result["hits"]["hits"][$x]['_source']['en_answer']; 
echo"<br><br>";
$x++; $no++;
endwhile;

library :

 public function searchDocsWithParameter($type, $query")
    {
        return $this->call($type . '/_search?' . http_build_query(array('q' => $q)));
    }

i already googling about it, nobody post about how it. thats why i ask to this forum. pls help me.

many thanks in return thanks

gutasaputra
  • 179
  • 1
  • 6
  • 20

1 Answers1

1

Maybe this will help you understanding how it should work:

Different result when using GET/POST in elastic search

but for me better option for you should be download elasticsearch library from composer and use this in your project:

https://philsturgeon.uk/php/2012/05/07/composer-with-codeigniter/

then you will be have a more extensive library to usage:

https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/index.html

Community
  • 1
  • 1
rad11
  • 1,561
  • 3
  • 15
  • 30