Skip to content

use weight in function_score throw exception #144

Closed
@colddew

Description

@colddew

as mentioned in #86 #113 , i had tried several manner to use weight in function_score exclusively, it does not work and throw MissingRequiredPropertyException. Is there a conclusion, it is a bug, or the wrong way to use ?

https://www.elastic.co/guide/en/elasticsearch/reference/7.16/query-dsl-function-score-query.html#function-weight

GET /_search
{
  "query": {
    "function_score": {
      "query": { "match_all": {} },
      "boost": "5", 
      "functions": [
        {
          "filter": { "match": { "test": "bar" } },
          "random_score": {}, 
          "weight": 23
        },
        {
          "filter": { "match": { "test": "cat" } },
          "weight": 42
        }
      ],
      "max_boost": 42,
      "score_mode": "max",
      "boost_mode": "multiply",
      "min_score": 42
    }
  }
}
# style 1
.functions(new FunctionScore.Builder().new ContainerBuilder().weight(1.0).build())

# style 2
.functions(fs -> fs.weight(1.0).new ContainerBuilder())

co.elastic.clients.util.MissingRequiredPropertyException: Missing required property 'Builder.<variant kind>'
	at co.elastic.clients.util.ApiTypeHelper.requireNonNull(ApiTypeHelper.java:76) ~[elasticsearch-java-7.16.3.jar:na]
	at co.elastic.clients.elasticsearch._types.query_dsl.FunctionScore.<init>(FunctionScore.java:121) ~[elasticsearch-java-7.16.3.jar:na]
	at co.elastic.clients.elasticsearch._types.query_dsl.FunctionScore.<init>(FunctionScore.java:54) ~[elasticsearch-java-7.16.3.jar:na]
	at co.elastic.clients.elasticsearch._types.query_dsl.FunctionScore$Builder.build(FunctionScore.java:376) ~[elasticsearch-java-7.16.3.jar:na]
	at co.elastic.clients.elasticsearch._types.query_dsl.FunctionScore$Builder$ContainerBuilder.build(FunctionScore.java:405) ~[elasticsearch-java-7.16.3.jar:na]
	at co.elastic.clients.elasticsearch._types.query_dsl.FunctionScore$Builder$ContainerBuilder.build(FunctionScore.java:379) ~[elasticsearch-java-7.16.3.jar:na]
	at co.elastic.clients.elasticsearch._types.query_dsl.FunctionScoreQuery$Builder.functions(FunctionScoreQuery.java:240) ~[elasticsearch-java-7.16.3.jar:na]
	at cn.plantlink.service.ElasticsearchService.lambda$null$22(ElasticsearchService.java:184) ~[classes/:na]
	at co.elastic.clients.elasticsearch._types.query_dsl.Query$Builder.functionScore(Query.java:1243) ~[elasticsearch-java-7.16.3.jar:na]
	at cn.plantlink.service.ElasticsearchService.lambda$null$23(ElasticsearchService.java:161) ~[classes/:na]
	at co.elastic.clients.elasticsearch.core.SearchRequest$Builder.query(SearchRequest.java:1742) ~[elasticsearch-java-7.16.3.jar:na]
	at cn.plantlink.service.ElasticsearchService.lambda$getInfoList$28(ElasticsearchService.java:160) ~[classes/:na]
	at co.elastic.clients.elasticsearch.ElasticsearchClient.search(ElasticsearchClient.java:1504) ~[elasticsearch-java-7.16.3.jar:na]
	at cn.plantlink.service.ElasticsearchService.getInfoList(ElasticsearchService.java:158) ~[classes/:na]
	at cn.plantlink.controller.ElasticsearchController.getInfoList(ElasticsearchController.java:52) ~[classes/:na]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_201]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_201]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_201]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_201]
	at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) ~[spring-web-5.3.14.jar:5.3.14]
	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:150) ~[spring-web-5.3.14.jar:5.3.14]
	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:117) ~[spring-webmvc-5.3.14.jar:5.3.14]
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895) ~[spring-webmvc-5.3.14.jar:5.3.14]
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808) ~[spring-webmvc-5.3.14.jar:5.3.14]
	at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.3.14.jar:5.3.14]
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1067) ~[spring-webmvc-5.3.14.jar:5.3.14]
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:963) ~[spring-webmvc-5.3.14.jar:5.3.14]
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) ~[spring-webmvc-5.3.14.jar:5.3.14]
	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898) ~[spring-webmvc-5.3.14.jar:5.3.14]
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:655) ~[tomcat-embed-core-9.0.56.jar:4.0.FR]
	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) ~[spring-webmvc-5.3.14.jar:5.3.14]
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:764) ~[tomcat-embed-core-9.0.56.jar:4.0.FR]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: SpecificationRelated to the API spec used to generate client codeCategory: BugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions