Skip to content

Instantly share code, notes, and snippets.

@dainiusjocas
Created October 4, 2021 14:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dainiusjocas/a59b2780c1238423be25511cbd5468da to your computer and use it in GitHub Desktop.
Save dainiusjocas/a59b2780c1238423be25511cbd5468da to your computer and use it in GitHub Desktop.
Semantic search Kibana session
DELETE semantic-search
PUT semantic-search
{
"settings": {
"analysis": {
"filter": {
"synonym_graph": {
"type": "synonym_graph",
"lenient": false,
"expand": false,
"synonyms": [
"taksas => taksas, šuo, žinduolis, gyvūnas",
"berno_zenenhundas => berno_zenenhundas, šuo, žinduolis, gyvūnas",
"šuo => šuo, žinduolis, gyvūnas",
"žinduolis => žinduolis, gyvūnas",
"katė => katė, žinduolis, gyvūnas"
]
}
},
"analyzer": {
"taxonomy_synonyms": {
"tokenizer": "standard",
"filter": [
"synonym_graph"
]
}
}
}
},
"mappings": {
"properties": {
"text": {
"type": "text"
},
"category": {
"type": "text",
"analyzer": "taxonomy_synonyms"
}
}
}
}
PUT semantic-search/_bulk
{ "index" : { "_id" : "1" } }
{ "text": "Šunys yra gerai", "category": "šuo"}
{ "index" : { "_id" : "2" } }
{ "text": "Taksai yra ilgi","category": "taksas"}
{ "index" : { "_id" : "3" } }
{ "text": "Žinduoliai žindo pienu", "category": "žinduolis"}
{ "index" : { "_id" : "4" } }
{ "text": "Katės nemėgsta vandens", "category": "katė"}
GET semantic-search/_refresh
GET semantic-search/_mtermvectors
{
"docs": [
{
"_id": "1",
"field_statistics": false,
"term_statistics": false,
"offsets": false,
"positions": false,
"fields": [
"category"
]
},
{
"_id": "2",
"field_statistics": false,
"term_statistics": false,
"offsets": false,
"positions": false,
"fields": [
"category"
]
},
{
"_id": "3",
"field_statistics": false,
"term_statistics": false,
"offsets": false,
"positions": false,
"fields": [
"category"
]
},
{
"_id": "4",
"field_statistics": false,
"term_statistics": false,
"offsets": false,
"positions": false,
"fields": [
"category"
]
}
]
}
GET semantic-search/_search
{
"explain": false,
"query": {
"bool": {
"should": [
{
"match": {
"category": {
"query": "taksas"
}
}
},
{
"match": {
"text": {
"query": "taksas"
}
}
}
]
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment