Hi there, I'm currently working on a face recognition project using Elasticsearch. I can't seem to get a working query for matching two datasets with each other. My most recent attempt is shown below the mapping. I was hoping to get some help here.
I have an index called face_recognition
(mapping below). What I want to accomplish with the query is the following;
- Filter by term: dataset =
input/test
. - For all filtered documents, find the top match of another dataset (filter the same index based on dataset =
input/celebs
) using thecosineSimilarity
function with the face_embedding values of both documents. - Show the top matching document from
input/celebs
for each document frominput/test
in the response
Please let me know if you need additional information or a more detailed explanation.
Mapping
{
"face_recognition": {
"mappings": {
"dynamic": "false",
"properties": {
"bottom_right": {
"type": "point"
},
"dataset": {
"type": "keyword"
},
"face_embedding": {
"type": "dense_vector",
"dims": 128,
"index": true,
"similarity": "l2_norm"
},
"file_name": {
"type": "keyword"
},
"height": {
"type": "integer"
},
"top_left": {
"type": "point"
},
"width": {
"type": "integer"
}
}
}
}
}
Non-working query
{
"query": {
"bool": {
"must": [
{
"match": {
"dataset": "input/test"
}
}
],
"should": [
{
"script_score": {
"query": {
"match": {
"dataset": "input/celebs"
}
},
"script": {
"source": "cosineSimilarity(params.query_vector, doc['face_embedding']) + 1.0",
"params": {
"query_vector": {
"dataset": "input/test",
"face_embedding": {
"type": "dense_vector",
"dims": 128,
"index": true,
"similarity": "l2_norm"
}
}
}
}
}
}
]
}
},
"sort": [
{
"_score": {
"order": "desc"
}
}
]
}
ES instance info
{
"name": "8ebe152fb75a",
"cluster_name": "docker-cluster",
"cluster_uuid": "ufSwSRHlQt2HHUtZccdhfw",
"version": {
"number": "8.5.3",
"build_flavor": "default",
"build_type": "docker",
"build_hash": "4ed5ee9afac63de92ec98f404ccbed7d3ba9584e",
"build_date": "2022-12-05T18:22:22.226119656Z",
"build_snapshot": false,
"lucene_version": "9.4.2",
"minimum_wire_compatibility_version": "7.17.0",
"minimum_index_compatibility_version": "7.0.0"
},
"tagline": "You Know, for Search"
}