lambda
lambda

Reputation: 1

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

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}

Upvotes: 0

Views: 18

Answers (0)

Related Questions