Elasticsearch returns post content empty if ?search= keyword is empty
- # 2 months, 3 weeks ago
I have an issue with elastic search if ?search= keyword si empty.
For example if I’m landing in my search page and there is no keywords the wpsolr returns some search results by default, everything it’s ok, but results are only with post title and post content it’s displayed with three dots (…).
In elastic search the content exists:
If I’m doing a search with a keyword the results are retrieved well and the content is displayed as it should.
I tried to boost content in admin (screen 2.3), but without results.
I’ve debugged a bit and I’ve seen that by default elastic search doesn’t return content with Search API.
There is a way to setup wpsolr and ES to return the post content by default?
PS: I’m using elasticsearch 6.8 cloud version.
Thank you!# 2 months, 3 weeks ago
Thanks for the feedback.
This is a general issue of search not always returning an highlighting for all results. See details for Elasticsearch at https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-highlighting.html.
WPSOLR is designed to retrieve only highlighting of results, not the source content, for performance reason. Some documents can embed pdf files, and therefore contain tens or hundreds of Mb of text. Retrieving all that text from the Elasticsearch server would kill it.
On the other hand, we could add some php code to replace the empty highlighting with an extract of the post. But in a multi-domain search, some posts retrieved are not from the current site. Therefore, there is no way to use get_post($post_id) to retrieve the extract.
The only acceptable solution I can foresee would be to build an Elasticsearch painless script (https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-scripting-painless.html). The script would return an extract from the content source, when the highlighting is empty.
Here is a beta release for your tests:
The solution chosen is to index the post excerpt, or the first sentences of the post content, and use it to replace empty snippets. It is fast simple, works for Solr and Elasticsearch, and is cross-domain compatible.
You’ll need to:
– Select “index excerpts” in screen 2.2
– Reindex all your data
Let me know of your conclusions.
Thanks for the beta test!
I tried with the last update but when I index the data I have an error:
An error or timeout occured.
Error code: parsererror
Error message: SyntaxError: Unexpected token P in JSON at position 0.
It may be because we’re using elementor and most of our pages are made with it?
I removed odd characters before indexing excerpts:
You must be logged in to reply to this topic.