Sort by location not working – Fatal Error
- prakashreddy.imduriParticipant1 year, 6 months ago #32960
Hi, I have added acf fields in format ( lat, long), and indexed all products.
Added location to sort filter, but on selecting it, nothing changes, and on reloading page with url containing sort filter(?s=report&wpsolr_sort=geolocation_str_desc), I can see this errorFatal error: Uncaught Elasticsearch\Common\Exceptions\BadRequest400Exception: {"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"can't sort on geo_point field without using specific sorting feature, like geo_distance"}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":
Geolocation extension is added and configured too as per the documentation
Can you help me with this ?- This topic was modified 1 year, 6 months ago by prakashreddy.imduri.
- This topic was modified 1 year, 6 months ago by prakashreddy.imduri.
wpsolrKeymaster1 year, 6 months ago #32965Did you activate and set the Geolocation add-on?
prakashreddy.imduriParticipant1 year, 6 months ago #32968Yes,
prakashreddy.imduriParticipant1 year, 6 months ago #32969I changed the custom field type of geolocation to text sortable, and it works, but I use it as geolocation its throwing fatal error
Is it okay to go with this?
One more issue is this code isnt working:
I did print_r($post), got these values into it
- This reply was modified 1 year, 6 months ago by prakashreddy.imduri.
prakashreddy.imduriParticipant1 year, 6 months ago #32973Not able to see the query monitor, as nav bar too is breaking on this error
Fatal error: Uncaught Exception: {"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"can't sort on geo_point field without using specific sorting feature, like geo_distance"}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"local_index","node":"a8xpkVcrRwSVMQ4H1196lQ","reason":{"type":"illegal_argument_exception","reason":"can't sort on geo_point field without using specific sorting feature, like geo_distance"}}],"caused_by":{"type":"illegal_argument_exception","reason":"can't sort on geo_point field without using specific sorting feature, like geo_distance","caused_by":{"type":"illegal_argument_exception","reason":"can't sort on geo_point field without using specific sorting feature, like geo_distance"}}},"status":400} in /code/wp-content/plugins/wpsolr-pro/wpsolr/core/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php on line 693 Call stack: Elasticsearch\Connections\Connection::process4xxError() wp-content/plugins/wpsolr-pro/wpsolr/core/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php:333 Elasticsearch\C\Connection::Elasticsearch\C\{closure}() wp-content/plugins/wpsolr-pro/wpsolr/core/vendor/react/promise/src/FulfilledPromise.php:28 React\Promise\FulfilledPromise::then() wp-content/plugins/wpsolr-pro/wpsolr/core/vendor/ezimuel/ringphp/src/Future/CompletedFutureValue.php:55 GuzzleHttp\R\F\CompletedFutureValue::then() wp-content/plugins/wpsolr-pro/wpsolr/core/vendor/ezimuel/ringphp/src/Core.php:341 GuzzleHttp\Ring\Core::proxy() wp-content/plugins/wpsolr-pro/wpsolr/core/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php:345 Elasticsearch\C\Connection::Elasticsearch\C\{closure}() wp-content/plugins/wpsolr-pro/wpsolr/core/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php:241 Elasticsearch\Connections\Connection::performRequest() wp-content/plugins/wpsolr-pro/wpsolr/core/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Transport.php:110 Elasticsearch\Transport::performRequest() wp-content/plugins/wpsolr-pro/wpsolr/core/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Client.php:1929 Elasticsearch\Client::performRequest() wp-content/plugins/wpsolr-pro/wpsolr/core/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Client.php:1353 Elasticsearch\Client::search() wp-content/plugins/wpsolr-pro/wpsolr/core/classes/engines/elasticsearch_php/class-wpsolr-searchelasticsearchclient.php:113 wpsolr\c\c\e\e\WPSOLR_SearchElasticsearchClient::search_engine_client_execute() wp-content/plugins/wpsolr-pro/wpsolr/core/classes/engines/class-wpsolr-abstractsearchclient.php:1053 wpsolr\c\c\e\WPSOLR_AbstractSearchClient::execute_query() wp-content/plugins/wpsolr-pro/wpsolr/core/classes/engines/class-wpsolr-abstractsearchclient.php:1008 wpsolr\c\c\e\WPSOLR_AbstractSearchClient::execute_wpsolr_query() wp-content/plugins/wpsolr-pro/wpsolr/core/classes/ui/class-wpsolr-query.php:497 wpsolr\c\c\u\WPSOLR_Query::get_posts() wp-includes/class-wp-query.php:3613 WP_Query::query() wp-includes/class-wp.php:648 WP::query_posts() wp-includes/class-wp.php:775 WP::main() wp-includes/functions.php:1330 wp() wp-blog-header.php:16 require() index.php:17
prakashreddy.imduriParticipant1 year, 6 months ago #32977this is my acf field :
prakashreddy.imduriParticipant1 year, 6 months ago #32981This is the field getting sent to index, I checked in debug turned on while send data
prakashreddy.imduriParticipant1 year, 6 months ago #32983How can we debug this ?
Failing in these both scenarios, I am getting use my location checkbox, browser message to allow location, but this page breaks. If I use text sortble for geolocation field, results arent sorted without any fatal error.
?s=report&wpsolr_sort=geolocation_str_desc
?s=report&wpsolr_is_geo=n&wpsolr_lat=15.3921558&wpsolr_long=73.9947563prakashreddy.imduriParticipant1 year, 6 months ago #32985Hi, is there any demo available related to geolocation, I believe some params in URLs aren’t getting passed causing the error.
This url has fatal error
?s=report&wpsolr_is_geo=y&wpsolr_lat=37.458&wpsolr_long=78.368but this below url works [results aren’t – sorting not working as expected though]
?s=report&wpsolr_is_geo=y&wpsolr_lat=37.458&wpsolr_long=78.368&wpsolr_sort=geo_distanceCan you share some demo url with url params, for me to test.
prakashreddy.imduriParticipant1 year, 6 months ago #32987Its just a normal text field :
I tried adding Lat,log and also (lat,log) in values, both having issues. Which is the correct way, with or without brackets?
As this error says “can’t sort on geo_point field without using specific sorting feature, like geo_distance”. Adding wpsolr_sort=geo_distance stops the error, but functionality not working.
prakashreddy.imduriParticipant1 year, 6 months ago #32988?s=best&wpsolr_is_geo=y&wpsolr_lat=17.457964&wpsolr_long=78.3687756&wpsolr_sort=geo_distance_desc
On Adding wpsolr_sort=geo_distance_desc to url, these are the results I am getting, no fatal error, but not sorted as per distance.
This is the Query monitor logged wpsolr query, as I avoided the fatal error with that string param in url
{ "from": 0, "size": 20, "track_total_hits": true, "highlight": { "require_field_match": false, "pre_tags": [""], "post_tags": ["<\/b>"], "fields": { "title": { "fragment_size": 100, "number_of_fragments": 1 } } }, "_source": ["id", "PID", "type", "meta_type_s", "title", "numcomments", "comments", "displaydate", "displaymodified", "*categories_str", "author", "*post_thumbnail_href_str", "*post_href_str", "snippet_s", "wpsolr_distance_geolocation_acf"], "query": { "function_score": { "functions": [{ "filter": { "match": { "product_visibility_str": "featured" } }, "weight": 1.1 }], "query": { "bool": { "must": { "query_string": { "fields": ["product_visibility_str^1.1", "title^9", "content^1.5"], "query": "(best)", "default_operator": "AND" } }, "filter": { "bool": { "must": [{ "bool": { "must_not": [{ "terms": { "post_status_s": ["draft", "pending", "trash", "future", "private", "auto-draft"] } }] } }, { "bool": { "must_not": [{ "terms": { "type": ["shop_order"] } }] } }, { "bool": { "should": [{ "bool": { "must_not": [{ "terms": { "type": ["product"] } }] } }, { "bool": { "should": [{ "bool": { "must_not": [{ "exists": { "field": "product_visibility_str" } }] } }, { "bool": { "must_not": [{ "terms": { "product_visibility_str": ["exclude-from-search"] } }] } }] } }] } }, { "bool": { "should": [{ "bool": { "must_not": [{ "bool": { "must": { "exists": { "field": "is_excluded_s" } } } }] } }, { "terms": { "is_excluded_s": ["n"] } }] } }, { "bool": { "must_not": [{ "terms": { "_id": ["wpsolr_doc_id_attachment"] } }] } }] } } } } } }, "post_filter": { "bool": { "must": [{ "bool": { "must": [{ "terms": { "type": ["product"] } }] } }] } }, "script_fields": { "wpsolr_distance_geolocation_acf": { "script": { "source": "doc[params.field].empty ? params.empty_value : doc[params.field].planeDistance(params.lat,params.lon)*0.001", "params": { "field": "geolocation_acf_ll", "empty_value": 40000, "lat": 17.457964, "lon": 78.3687756 }, "lang": "painless" } } }, "aggs": { "flat_hierarchy_industry_str": { "filter": { "bool": { "must": [{ "bool": { "must": [{ "terms": { "type": ["product"] } }] } }] } }, "aggs": { "flat_hierarchy_industry_str": { "filter": { "match_all": {} }, "aggs": { "flat_hierarchy_industry_str": { "terms": { "field": "flat_hierarchy_industry_str", "size": 200000, "order": { "_key": "asc" } } } } } } }, "flat_hierarchy_geography_str": { "filter": { "bool": { "must": [{ "bool": { "must": [{ "terms": { "type": ["product"] } }] } }] } }, "aggs": { "flat_hierarchy_geography_str": { "filter": { "match_all": {} }, "aggs": { "flat_hierarchy_geography_str": { "terms": { "field": "flat_hierarchy_geography_str", "size": 200000, "order": { "_key": "asc" } } } } } } }, "flat_hierarchy_report_type_str": { "filter": { "bool": { "must": [{ "bool": { "must": [{ "terms": { "type": ["product"] } }] } }] } }, "aggs": { "flat_hierarchy_report_type_str": { "filter": { "match_all": {} }, "aggs": { "flat_hierarchy_report_type_str": { "terms": { "field": "flat_hierarchy_report_type_str", "size": 200000, "order": { "_key": "asc" } } } } } } }, "flat_hierarchy_themes_str": { "filter": { "bool": { "must": [{ "bool": { "must": [{ "terms": { "type": ["product"] } }] } }] } }, "aggs": { "flat_hierarchy_themes_str": { "filter": { "match_all": {} }, "aggs": { "flat_hierarchy_themes_str": { "terms": { "field": "flat_hierarchy_themes_str", "size": 200000, "order": { "_key": "asc" } } } } } } }, "publication_date_dt": { "filter": { "bool": { "must": [{ "bool": { "must": [{ "terms": { "type": ["product"] } }] } }] } }, "aggs": { "publication_date_dt": { "filter": { "match_all": {} }, "aggs": { "publication_date_dt": { "stats": { "field": "publication_date_dt" } } } } } }, "_price_f": { "filter": { "bool": { "must": [{ "bool": { "must": [{ "terms": { "type": ["product"] } }] } }] } }, "aggs": { "_price_f": { "filter": { "match_all": {} }, "aggs": { "_price_f": { "range": { "field": "_price_f", "ranges": [{ "to": "0" }, { "from": 0, "to": 2000 }, { "from": 2000, "to": 4000 }, { "from": 4000, "to": 6000 }, { "from": 6000, "to": 8000 }, { "from": 8000, "to": 10000 }, { "from": "10000" }] } } } } } } } }
wpsolrKeymaster1 year, 6 months ago #32989I just replicated your configuration locally, with success.
– ACF “text” field geolocation_acf
– Url:
/?s=&wpsolr_is_geo=y&wpsolr_sort=geolocation_acf_str_desc&wpsolr_lat=44.834999&wpsolr_long=-0.575490
– Elasticsearch sort in Query monitor:
"sort": [ { "_geo_distance": { "geolocation_acf_ll": { "lat": "44.834999", "lon": "-0.575490" }, "order": "desc", "unit": "km", "mode": "min", "distance_type": "plane" } } ]
You must be logged in to reply to this topic.