Git Product home page Git Product logo

Comments (5)

swallez avatar swallez commented on July 21, 2024

Thanks for the report @neowu. There is indeed an issue on this type's deserialization and we were able to identify it with the samples you've provided. We're working on a fix.

from elasticsearch-java.

WilliamsDL avatar WilliamsDL commented on July 21, 2024

Adding myself for visibility. This is a show stopping bug for me and my team. Our suggestions do not work currently because of this issue.

` Map<String, FieldSuggester> suggestersMap = new HashMap<>();
suggestersMap.put(field + ConstantsHelper.COMPLETION_STANDARD,
CompletionSuggester.of(suggester -> suggester
.field(field + ConstantsHelper.COMPLETION_STANDARD)
.prefix(query)
.skipDuplicates(true)
.size(ConstantsHelper.FIFTEEN_LITERAL))
._toFieldSuggester());

SearchRequest request = SearchRequest.of(r -> r
.index(elasticConfig.getSuggestionIndex())
.size(elasticConfig.getSearchHitSize())
.timeout(String.valueOf(String.format("%sms", elasticConfig.getConnectTimeout())))
.suggest(x -> x.text(query).suggesters(suggestersMap))
);`

from elasticsearch-java.

cyrillesondag avatar cyrillesondag commented on July 21, 2024

Hello,

For the Java API there is 2 problemes IMO:

  • First suggest options map are determined by the map item's key : completion/phrase/term =+ # + <suggestion_name>
    This suggest type is lost in the option's array parsing.
  • Second in the UnionDeserializer members of each kind are flatten in a Map indexed by field name. Unfortunatly fields names are not unique by types, so this case "completion" options are miss interpreted as "term"options.

Here is the flatten part of the union Deserializer :

JsonpDeserializer<?> unwrapped = DelegatingDeserializer.unwrap(deserializer);
if (unwrapped instanceof ObjectDeserializer) {
    ObjectDeserializer<?> od = (ObjectDeserializer<?>) unwrapped;
    Set<String> allFields = od.fieldNames();
    Set<String> fields = new HashSet<>(allFields); // copy to update
    for (UnionDeserializer.SingleMemberHandler<Union, Kind, Member> member: objectMembers) {
        // Remove respective fields on both sides to keep specific ones
        fields.removeAll(member.fields);
        member.fields.removeAll(allFields);
    }
    UnionDeserializer.SingleMemberHandler<Union, Kind, Member> member = new SingleMemberHandler<>(tag, deserializer, fields);
    objectMembers.add(member);
    if (od.shortcutProperty() != null) {
        // also add it as a string
        addMember(Event.VALUE_STRING, tag, member);
    }
} else {
    UnionDeserializer.SingleMemberHandler<Union, Kind, Member> member = new SingleMemberHandler<>(tag, deserializer);
    for (Event e: deserializer.nativeEvents()) {
        addMember(e, tag, member);
    }
}

May be kepping the ObjectDeserializer "as is" and implementing a "best macth" by field names in the UnionDeserializer#deserialize method will do the tricks ?
Or a safer option is to pass kind type information from map's key while processing the suggestion item.

 if (member == null && event == Event.START_OBJECT && !objectMembers.isEmpty()) {
    // Parse as an object to find matching field names
    JsonObject object = parser.getObject();

    for (String field: object.keySet()) {
        member = objectMembers.get(field);
        if (member != null) {
            break;
        }
    }

    if (member == null) {
        member = fallbackObjectMember;
    }

    if (member != null) {
        // Traverse the object we have inspected
        parser = JsonpUtils.objectParser(object, mapper);
        event = parser.next();
    }
}

from elasticsearch-java.

swallez avatar swallez commented on July 21, 2024

The API specification has been fixed in elastic/elasticsearch-specification#1301

The next pass of code generation will fix the issue.

from elasticsearch-java.

zhaoxin-jia-tfs avatar zhaoxin-jia-tfs commented on July 21, 2024

SearchRequest request = SearchRequest.of(r -> r
.index(elasticConfig.getSuggestionIndex())
.size(elasticConfig.getSearchHitSize())
.timeout(String.valueOf(String.format("%sms", elasticConfig.getConnectTimeout())))
.suggest(x -> x.text(query).suggesters(suggestersMap))
@neowu
had you ever resolved this problem? I still occur this problem. can you help me?

from elasticsearch-java.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.