Skip to content

CompletionSuggester not working because prefix is placed at wrong position in JSON #150

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

Closed
Lenoirio opened this issue Feb 1, 2022 · 4 comments
Labels
Area: Specification Related to the API spec used to generate client code v7.17.4 v8.2.1

Comments

@Lenoirio
Copy link

Lenoirio commented Feb 1, 2022

I'm migrating from the old high-level-client and I'm having an issue with the CompletionSuggester (using 7.16.3 right now)

As the doc at https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters.html states, a request looks like this

POST music/_search?pretty
{
  "suggest": {
    "song-suggest": {
      "prefix": "nir",        
      "completion": {         
          "field": "suggest"  
      }
    }
  }
}

As you can see the prefix is placed in front of the "completion"-object. When I use your CompletionSuggester it will place the prefix inside the "completion"-object. As a result ElasticSearch gives me this error:

[2022-02-01T14:26:53,829][ERROR][c.a.e.AuthenticationPlugin] [SAG-21X1703] org.elasticsearch.xcontent.XContentParseException: [1:257] [completion] unknown field [prefix]

Am I doing something wrong or is this a bug? The old java-client was doing it right and also placed the prefix in front of the "completion"-object.

Thank you very much!

@sothawo
Copy link
Contributor

sothawo commented Feb 19, 2022

That just bit me as well.

The old RHLC code passed the prefix argument to it's parent, so it ended up at the right place:

    public CompletionSuggestionBuilder prefix(String prefix, Fuzziness fuzziness) {
        super.prefix(prefix);
        this.fuzzyOptions = new FuzzyOptions.Builder().setFuzziness(fuzziness).build();
        return this;
    }

@KamilGlo
Copy link

KamilGlo commented Mar 2, 2022

This also occurs for term suggester, using client v7.16.3.
Creating a request for suggestion like

final SearchRequest request =
    new SearchRequest.Builder()
                     .index(getIndexName())
                     .suggest(s ->
                              s.suggesters(fieldName + "_suggestion",
                                           FieldSuggester.of(f -> f.term(term -> term.field(fieldName)
                                                                                     .text(searchFieldText)
                                                                                     .minWordLength(2)))))
                     .build();

builds a request

{
  "suggest":
  {
    "title_suggestion":
    {
      "term":
      {
        "field":"title",
        "min_word_length":2,
        "text":"ths is nt rght"
      }
    }
  }
}

and server returns

co.elastic.clients.elasticsearch._types.ElasticsearchException: [es/search] failed: [parsing_exception] suggester[term] doesn't support field [text]

@swallez
Copy link
Member

swallez commented Mar 22, 2022

Thanks for reporting this. It's an issue in the API specification used to produce the Java code.

elastic/elasticsearch-specification#1567 has been opened to solve it, and the Java client will be updated once it's fixed.

@swallez
Copy link
Member

swallez commented May 6, 2022

This has been fixed in 0a47bd2 and will be part of version 8.2.1 (it's already available in the nightly snapshots).

Also fixed in 31a742a that will be in version 7.17.4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Specification Related to the API spec used to generate client code v7.17.4 v8.2.1
Projects
None yet
Development

No branches or pull requests

4 participants