Skip to content

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

Closed
@wuxiansen

Description

@wuxiansen

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. 🧑‍💻

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions