Elasticsearch returns post content empty if ?search= keyword is empty

  • iuliansafta
    Participant
    # 4 months, 4 weeks ago

    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 (…).

    View post on imgur.com

    In elastic search the content exists:

    View post on imgur.com

    If I’m doing a search with a keyword the results are retrieved well and the content is displayed as it should.

    View post on imgur.com

    I tried to boost content in admin (screen 2.3), but without results.

    View post on imgur.com

    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!

    wpsolr
    Keymaster
    # 4 months, 4 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.

    wpsolr
    Keymaster
    # 4 months, 3 weeks ago

    Here is a beta release for your tests:
    https://www.dropbox.com/s/mdr78ogq64lvab5/wpsolr-pro-empty-snippets.zip?dl=0

    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.

    iuliansafta
    Participant
    # 4 months, 3 weeks ago

    Hi,

    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!

    wpsolr
    Keymaster
    # 4 months, 3 weeks ago

    And if you deselect 2.2 option “Index excerpt”?

    iuliansafta
    Participant
    # 4 months, 3 weeks ago

    I have the same error, If I’m trying with the last version it’s working well

    wpsolr
    Keymaster
    # 4 months, 3 weeks ago
    iuliansafta
    Participant
    # 4 months, 3 weeks ago

    I have the same error with Index post excerpt = true, without it index well.

    wpsolr
    Keymaster
    # 4 months, 3 weeks ago

    Reindex, with batch size “1”, and debug “on”.

    When it stops with error, check the post id. Edit the post, and try to save it to index it.

    iuliansafta
    Participant
    # 4 months, 3 weeks ago

    It seams to work, but unfortunately I have to repeat this process for every post and are quite a lot of them.

    wpsolr
    Keymaster
    # 4 months, 3 weeks ago

    The test was to detect the problem, not to index manually!

    What do you mean with “It seams to work” ? You should also get an error on saving the posts.

    iuliansafta
    Participant
    # 4 months, 3 weeks ago

    It 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.

    wpsolr
    Keymaster
    # 4 months, 3 weeks ago

    What happened since ?
    “I have the same error with Index post excerpt = true, without it index well.”

    iuliansafta
    Participant
    # 4 months, 3 weeks ago

    If 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.

    wpsolr
    Keymaster
    # 4 months, 3 weeks ago

    This is strange. The same code is executed in both situations.

    When indexing with the batch, are all posts in error, or some are indexed?

Viewing 15 posts - 1 through 15 (of 18 total)

You must be logged in to reply to this topic.