Last active
July 7, 2016 21:33
-
-
Save eliasah/0e9da58ae4ea4e8e4ecb to your computer and use it in GitHub Desktop.
[elasticsearch] compute K-nearest neighbor for training a classifier purposes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
########################################################################################## | |
# use case: training a classifier | |
# | |
# Many systems classify documents by assigning “tag” or “category” fields. Classifying | |
# documents can be a tedious manual process and so in this example we will train a classifier | |
# to automatically spot keywords in new documents that suggest a suitable category. | |
curl -XGET "http://localhost:9200/products_fr/_search" -d' | |
{ | |
"query": { | |
"function_score": { | |
"query": { | |
"query_string": { | |
"query": "samsung", | |
"default_operator": "AND", | |
"fields": [ | |
"title^3", | |
"description" | |
] | |
} | |
}, | |
"functions": [ | |
{ | |
"script_score": { | |
"script": "_score * log1p(doc[\"hits\"].value) + log1p(doc[\"hits\"].value)" | |
} | |
} | |
] | |
} | |
}, | |
"aggregations": { | |
"knn": { | |
"significant_terms": { | |
"field": "title","size": 3 | |
} | |
} | |
} | |
, "size": 0 | |
}' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
########################################################################################## | |
# use case: training a classifier | |
# | |
# Many systems classify documents by assigning “tag” or “category” fields. Classifying | |
# documents can be a tedious manual process and so in this example we will train a classifier | |
# to automatically spot keywords in new documents that suggest a suitable category. | |
curl -XGET "http://localhost:9200/products_fr/_search" -d' | |
{ | |
"query": { | |
"query_string": { | |
"fields": ["title","description"], | |
"query": "galaxy" | |
} | |
}, | |
"aggregations": { | |
"knn": { | |
"significant_terms": { | |
"field": "title","size": 3 | |
} | |
} | |
} | |
, "size": 0 | |
}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nothing related to K-Nearest-Neighbour here. Provided queries are Aggregations. It is not even "More-Like-This" type.