-
Notifications
You must be signed in to change notification settings - Fork 733
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update to support 5.4 #1321
Update to support 5.4 #1321
Conversation
@mtdavidson I restarted the build as the xdebug failures were not related to this change. But now there seem to be some other problems. |
Thanks @ruflin I am working on the problems. Its a bit of a mess of issues, mainly due to content type checking. elastic/elasticsearch#23452 Since we set the default type to be Changing the default content/type to
But I'm not convinced that is the best approach. The better approach would probably be to keep that default and start getting rid of any uses of |
@mtdavidson when $data is an array, using
It's why I've set the default to More practically I'd be for tracking everywhere we send a string and specify the content/type to use on the call sites. I quickly checked public function analyze($text, $args = [])
{
$endpoint = new Analyze();
$endpoint->setBody($text);
$args['client']['headers'][] = 'Content-Type: text/plain';
$endpoint->setParams($args);
$data = $this->requestEndpoint($endpoint)->getData();
// Support for "Explain" parameter, that returns a different response structure from Elastic
// @see: https://www.elastic.co/guide/en/elasticsearch/reference/current/_explain_analyze.html
if (isset($args['explain']) && $args['explain']) {
return $data['detail'];
}
return $data['tokens'];
}
} Then in Client.php public function requestEndpoint(AbstractEndpoint $endpoint)
{
$options = $endpoint->getOptions();
$contentType = Request::DEFAULT_CONTENT_TYPE;
if(!empty($options['client']['headers'])) {
// TODO: a method to find and extract the Content-Type header
// from a list of headers
$contentType = findContentType($options['client']['headers']);
}
return $this->request(
ltrim($endpoint->getURI(), '/'),
$endpoint->getMethod(),
null === $endpoint->getBody() ? [] : $endpoint->getBody(),
$endpoint->getParams(),
$contentType
);
} I'm not sure that this option (client/headers) is compatible with |
@nomoa Thanks a lot for investigating this and sharing the details. One thing that is not clear to me yet is how many place do we have where Elastica sends a string? |
I don't think we have many of them, elasticsearch REST endpoints that accept non-json are rare:
My feeling is that elastic wants to deprecate and remove all these ambiguities by accepting only bodies that are in a known XContent. So one easy fix I haven't thought yesterday would be to always send an array so that it always matches content-type/json (except in the case of bulk where it's properly handled with a custom content/type) @mtdavidson would you mind testing if changing public function analyze($text, $args = [])
{
$endpoint = new Analyze();
$endpoint->setBody(['text' => $text]); // use an array instead of a plain string
$endpoint->setParams($args);
// [...] fixes the issue without changing the default content/type to text/plain |
@nomoa Sure thing I'll give it a go. |
That does work @nomoa However does mean people will have to change anywhere they have called public function testRequestEndpoint()
{
...
$endpoint = new Analyze();
$endpoint->setIndex('fooIndex');
$endpoint->setBody('foo');
...
} might just have to accept its going to be a bit of a breaking upgrade on a few things. To answer your previous question at least from a test perspective not to many things that use a text body these are the ones we see errors with
|
@mtdavidson thanks! Note that the issues related to Scroll have just been fixed. You might just merge master again to your PR. |
Great call on the merge @nomoa that and the change to use |
+1 on moving away on using strings in all places. I also assume endpoints so far are rarely used and the above is more a "bug" on our implementation side. Anyone wants to do a follow up PR to fix the other "problems"? |
@mtdavidson Merged. Thanks a lot for the work on this one. |
No problem glad we got there in the end with a good solution thanks to @nomoa I can get back to adding Adjacency Matrix Aggregation which was the main point of the upgrade. |
Hello, big thanks for this contribution @mtdavidson! @ruflin do you plan to publish a new release - including the support of ES 5.4 - soon? I know you release often, this is why I'm wondering if I can rely on master branch right now and use ES 5.4 in production :) Have a nice day Mickaël |
@mickaelandrieu Not sure what statement I should make here ;-) I do plan a release in the near future but obviously can't guarantee that it will not contain any breaking changes. As there will be some breaking changes for 6.0 I probably will branch off before we introduce the first breaking change. You should be save with master until a 5.3 or 5.4 release is out, but obviously at your own risk ;-) |
DFS_QUERY_AND_FETCH
/QUERY_AND_FETCH
have been removed in 5.3.0 ( https://www.elastic.co/guide/en/elasticsearch/reference/5.3/release-notes-5.3.0.html )OPTION_SEARCH_TYPE_DFS_QUERY_AND_FETCH
andOPTION_SEARCH_TYPE_QUERY_AND_FETCH
have been removed fromElastica\Search
. We could keep these to allow for their use in 5.2 and below but I don't think they are highly used so maintaining the backwards compatibility is not key.