Skip to content

Instantly share code, notes, and snippets.

@alexGitSpace
Created July 2, 2020 07:39
Show Gist options
  • Save alexGitSpace/3a3e2371c540a34a1fc670249109ce32 to your computer and use it in GitHub Desktop.
Save alexGitSpace/3a3e2371c540a34a1fc670249109ce32 to your computer and use it in GitHub Desktop.
ElasticSearch. Test work with dense_vector type
PUT /test_dense_vector
{
"mappings": {
"properties" : {
"title" : {
"type": "text"
},
"title_vector": {
"type": "dense_vector",
"dims": 3
}
}
}
}
POST /test_dense_vector/_bulk
{ "index": { "_id": 1 }}
{ "title" : "big hat", "title_vector": [1, 1, 1]}
{ "index": { "_id": 2 }}
{ "title" : "big black hat", "title_vector": [3, 5, 7]}
{ "index": { "_id": 3 }}
{ "title" : "not big hat", "title_vector": [100, 200, 300]}
GET test_dense_vector/_search
{
"query": {
"function_score": {
"query": {
"match_all": {
}
},
"functions": [
{
"script_score": {
"script": {
"source": "cosineSimilarity(params.query_vector, 'title_vector')",
"params": {"query_vector":[1,1,1]}
}
}
}
]
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment