-
Notifications
You must be signed in to change notification settings - Fork 13
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
AppSearch how to use sort? #11
Comments
@kamil-karkus the use Elastic\EnterpriseSearch\AppSearch\Schema\SimpleObject;
$sort = new SimpleObject();
$sort->fieldA = 'desc';
$sort->fieldB = 'desc';
$searchRequestParams->sort = $sort; |
Already tried this and got 400 bad request, I'll provide more details later today |
Ok, please paste the full PHP code including the endpoint usage, thanks. |
@ezimuel I'm sorry for the delay. Package version
Code snippet $appSearch = $this->client->appSearch();
$searchRequestParams = new SearchRequestParams();
$searchRequestParams->query = $query;
$searchRequestParams->precision = 8;
$searchRequestParams->sort = [[Enum::KEY_IN_STOCK => 'desc'], [Enum::KEY_NET_PRICE => 'desc']];
$current = max(1, $page);
$size = min($limit, 1000);
$pagination = new \stdClass();
$pagination->current = $current;
$pagination->size = $size;
$searchRequestParams->page = $pagination;
$response = $appSearch
->search(new Search(Enum::ENGINE_NAME_PRODUCTS, $searchRequestParams))
->asArray(); Request body {"page":{"current":1,"size":100},"query":"long","sort":[{"in_stock":"desc"},{"net_price":"desc"}],"precision":8} Response code 200 Package version
Code snippet $appSearch = $this->client->appSearch();
$searchRequestParams = new SearchRequestParams($query);
$searchRequestParams->precision = 8;
$sort = new SimpleObject();
$key1 = Enum::KEY_IN_STOCK;
$sort->$key1 = 'desc';
$key2 = Enum::KEY_NET_PRICE;
$sort->$key2 = 'desc';
$searchRequestParams->sort = $sort;
$current = max(1, $page);
$size = min($limit, 1000);
$pagination = new PaginationResponseObject();
$pagination->current = $current;
$pagination->size = $size;
$searchRequestParams->page = $pagination;
$response = $appSearch
->search(new Search(Enum::ENGINE_NAME_PRODUCTS, $searchRequestParams))
->asArray(); Request body (sort isn't serialized correctly) {"query":"long","page":{"current":1,"size":100},"sort":{"in_stock":"desc","net_price":"desc"},"precision":8} Response code 400 Response body {"errors":["Sort contains an object with more than one key: in_stock and net_price"]} |
I'm seeing the same issue as @kamil-karkus. This code works when only sorting by one field, but I get a 400 Bad Request as soon as I add more than one field as @ezimuel did in this example. |
I found the issue, the |
@ezimuel I don't want to rush you but is there any news? |
Fixed in v7.17.0, sorry for the delay 😰 |
This is still broken for me. I'm using the dev-master branch and App Search 8.2 but still getting this error. {
"errors": [
"Sort contains an object with more than one key: title and title2"
]
} here's a basic test I did. $params = new SearchRequestParams('hey');
$params->sort = new SimpleObject();
$params->sort->title = 'asc';
$params->sort->title2 = 'asc';
$response = $this->client->search(new Search('local-elements', $params)); not sure if it makes sense for sort to be typed as a To be on the safe side all the |
ah you know what, looks like master is out of sync with the changes made to 7.17 to fix this. Any chance those can get merged in to the master branch? |
@myleshyson we did not release the |
I cannot figure out how to assing correct
SimpleObject
inSearchRequestParams
to sort results by e.g. fieldA and then fieldB.In previous package versions it wasn't type-hinted property so I could do something like this:
$searchRequestParams->sort = [['fieldA' => 'desc'], ['fieldB' => 'desc']];
But now it's type-hinted property so I can't do this.
Is it possible to provide OAS for enterprise search or OAS isn't flexible enough?
The text was updated successfully, but these errors were encountered: