-
Notifications
You must be signed in to change notification settings - Fork 243
result from using search method on model is different from that when i GET url exposed by elastic search #92
Comments
It builds a different query, using a Request Body instead of URL-params. I think what's fired to Elastic is:
|
@kronthto i agree. now i use shell_exec('curl http://localhost:9200/my_index/posts/_search?q=content:'.request('q')) as a replacement. |
If you need to do it that way you could at least use: file_get_contents('http://localhost:9200/my_index/posts/_search?q=content:'.request('q')) which is probably faster and more secure than Using Scout would directly map the results to Model-entities, so it would be nice to solve your initial problem. You could try modifying what is sent to ES using the callback-function parameter of the |
thx a lot. |
so far i have made it to split chinese characters. but a new problem arises: i have no idea how to strip html in my content, https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-htmlstrip-charfilter.html copy from stackoverflow:
|
I've never actually done that, but I think you need to define the HTMLStrip-filter as a normalizer type to your index and then add this normalizer to the field using the PUT-mapping API. It could be something like (not tested):
(inspired by https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-normalizers.html) |
PUT config to my_index and POST url like btw, it seems using return App\Docs::search($req->search, function($engine, $query) {
$query['body'] = [
'query' => [
'multi_match' => [
'query' => request('q'),
'fields' => ['name', 'rich_text']
]
],
'highlight' => [
'fields' => [
'name' => [
'force_source' => true
],
'rich_text' => [
'force_source' => true
]
]
]
];
return $engine->search($query);
})->paginate(); but value returned doesn't contain
it will be very kind of u to explain it ? |
When using laravel-scout-elastic/src/ElasticsearchEngine.php Lines 217 to 222 in 97deb01
This behaviour is intended for Scout-drivers. So, yes, |
3q very much, i've changed to elasticsearch-php, by which i can get raw data returned from elasticsearch and orginize them on my own. well, last question $params = array(
'http' => array(
'method' => 'POST',
'header' => 'Content-Type: application/json',
'content' => http_build_query([
'analyzer' => 'my_analyzer',
'text' => $value['_source']['rich_text']
])
)
);
$url = config('scout.elasticsearch.hosts')[0] . '/' . config('scout.elasticsearch.index') . '/_analyze';
$context = stream_context_create($params);
dd($result = file_get_contents($url, false, $context)); but the result is different from what i get on Postman, should i use http_build_query here? |
elasticsearch-php is what this library here uses under the hood anyways: laravel-scout-elastic/composer.json Line 8 in 97deb01
I think In general, if you want to do HTTP Requests in PHP I can only recommend using Guzzle, it makes the code so much cleaner / easier to read because you don't have to deal with $response = $client->request('POST', config('scout.elasticsearch.hosts')[0] . '/' . config('scout.elasticsearch.index') . '/_analyze', ['json' =>
[
'analyzer' => 'my_analyzer',
'text' => $value['_source']['rich_text']
]
]); |
excellent ! time to close this issue. feel very grateful for your help. |
Hi,
when i use
dd(App\Posts::search('场景1')->get())
, the result iswhile what i get from
http://localhost:9200/my_index/posts/_search?q=content:场景1
iswonder why ik doesn't work.
my
config/scout.php
is the same as that on readme.The text was updated successfully, but these errors were encountered: