Elasticsearch returns post content empty if ?search= keyword is empty
-
iuliansaftaParticipant3 years, 10 months ago #13552
Hello,
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!
wpsolrKeymaster3 years, 10 months ago #13556Thanks 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.
wpsolrKeymaster3 years, 10 months ago #13603Here is a beta release for your tests:
https://www.dropbox.com/s/mdr78ogq64lvab5/wpsolr-pro-empty-snippets.zip?dl=0The 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 dataLet me know of your conclusions.
iuliansaftaParticipant3 years, 10 months ago #13604Hi,
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?
Thanks!
iuliansaftaParticipant3 years, 10 months ago #13606I have the same error, If I’m trying with the last version it’s working well
wpsolrKeymaster3 years, 10 months ago #13607I removed odd characters before indexing excerpts:
https://www.dropbox.com/s/946pk5os2x2y597/wpsolr-pro-empty-snippets-1.zip?dl=0iuliansaftaParticipant3 years, 10 months ago #13608I have the same error with Index post excerpt = true, without it index well.
iuliansaftaParticipant3 years, 10 months ago #13610It seams to work, but unfortunately I have to repeat this process for every post and are quite a lot of them.
iuliansaftaParticipant3 years, 10 months ago #13612It seams to work: for the posts that are indexed the content appears in the default search.
I have not got any error when I saved the post.iuliansaftaParticipant3 years, 10 months ago #13614If I’m saving the post manually the index works ok, If I’m not I have the error with: SyntaxError: Unexpected token P in JSON at position 0.
For the posts that are indexed the content is displayed ok.
You must be logged in to reply to this topic.