Skip to content

SDE 4.x, 5.x How to use custom similarity? #2424

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
wuxiansen opened this issue Jan 9, 2023 · 3 comments · Fixed by #2429
Closed

SDE 4.x, 5.x How to use custom similarity? #2424

wuxiansen opened this issue Jan 9, 2023 · 3 comments · Fixed by #2429
Labels
type: enhancement A general enhancement

Comments

@wuxiansen
Copy link

wuxiansen commented Jan 9, 2023

Similarity is defined by index,now I don't know how to use it.
Similarity now defines Enum, not String.

{
  "index": {
    "similarity": {
      "my_similarity": {
        "type": "DFR",
        "basic_model": "g",
        "after_effect": "l",
        "normalization": "h2",
        "normalization.h2.c": "3.0"
      }
    }
  }
}
public enum Similarity {
	Default("default"), BM25("BM25"), classic("classic"), Boolean("boolean");
         ...
}

// use

class Entity {

    @Field(type = FieldType.Text, similarity = Similarity.xxx)
    private String message;

}

/**
* @since 4.0
*/
Similarity similarity() default Similarity.Default;

// MappingParameters.java
if (similarity != Similarity.Default) {
	objectNode.put(FIELD_PARAM_SIMILARITY, similarity.toString());
}

I tried specifying the default similarity index.similarity.default.type: my_similarity in elasticsearch.yml, but that became global

Or instead of using Field annotations, use Mapping altogether.

If Similarity defines String, wouldn't it be easier to extend?

eg:

class Entity {

    //     @Field(type = FieldType.Text, similarity = "BM25" or "boolean" )
    @Field(type = FieldType.Text, similarity = "my_similarity")
    private String message;

}

If think this suggestion is good, I'd be happy to optimize this issue for this. 🧑‍💻

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jan 9, 2023
@sothawo
Copy link
Collaborator

sothawo commented Jan 9, 2023

No, we won't change to String, because that would be a breaking change for existing users. I got a vague idea of how this can be solved, have to think about it.

@sothawo sothawo added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Jan 9, 2023
@sothawo
Copy link
Collaborator

sothawo commented Jan 14, 2023

Seems we have to do the breaking change to a String, as we cannot have interfaces as annotation properties.

@wuxiansen
Copy link
Author

wuxiansen commented Jan 16, 2023

I've tried to change similarity to an interface to reduce the impact on users. But the value of the annotation mode attribute must be a constant.

Seems we have to do the breaking change to a String, as we cannot have interfaces as annotation properties.

sothawo added a commit to sothawo/spring-data-elasticsearch that referenced this issue Jan 19, 2023
sothawo added a commit that referenced this issue Jan 19, 2023
Original Pull Request #2429
Closes #2424
@sothawo sothawo added this to the 5.1 M1 (2023.0.0) milestone Jan 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants