Skip to content

How to Implement Complex Queries (Vector Queries) in Spring Data Elasticsearch #3039

Closed as not planned
@MrWangGang

Description

@MrWangGang

The following code will throw an exception: [es/search] failed: [parsing_exception] unknown query [query].


    @Query(value = """
{
  "query": {
    "script_score": {
      "query": {
        "match_all": {}
      },
      "script": {
        "source": "cosineSimilarity(params.vector, doc['nameVector']) + cosineSimilarity(params.vector, doc['descriptionVector'])",
        "params": {
          "vector": ?0
        }
      }
    }
  },
  "sort": [
    { "_score": { "order": "desc" } }
  ]
}
""")
Flux<SearchHit<ClubPO>> queryClubs(List<Double> vector);

The following code can run successfully.


    @Query("""
{
  "script_score": {
    "query": {
      "match_all": {}
    },
    "script": {
      "source": "cosineSimilarity(params.vector, doc['nameVector']) + cosineSimilarity(params.vector, doc['descriptionVector'])",
      "params": {
        "vector": ?0
      }
    }
  }
}
""")
    Flux<SearchHit<ClubPO>> queryClubs(List<Double> vector);

What should I do?

Are there any other annotations? For example, ones that support more raw query syntax?

{"error":{"root_cause":[{"type":"parsing_exception","reason":"unknown query [query]","line":2,"col":12}],"type":"parsing_exception","reason":"unknown query [query]","line":2,"col":12,"caused_by":{"type":"named_object_not_found_exception","reason":"[2:12] unknown field [query]"}},"status":400}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions