Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
termInfo = _index[field].get(term,_PAYLOADS);
score = 0;
for (pos : termInfo) {
score = score + pos.payloadAsFloat(0);
}
return score;
curl -XPUT "http://localhost:9200/syn" -d'
{
"settings": {
"index": {
"analysis": {
"analyzer": {
"boosted_syn" : {
"tokenizer" : "whitespace",
"filter" : [
"lowercase",
"syns",
"delimited_payload_filter"
]
}
},
"filter" : {
"syns" : {
"type" : "synonym",
"synonyms" : [
"potato=>vegetable|3",
"tomato=>vegetable|2",
"carrot=>vegetable|1"
]
}
}
}
}
},
"mappings": {
"data" : {
"properties": {
"title" : {
"type": "string",
"analyzer": "boosted_syn"
}
}
}
}
}'
curl -XPOST "http://localhost:9200/syn/data/1" -d'
{
"title" : "vegetable"
}'
curl -XPOST "http://localhost:9200/syn/data/2" -d'
{
"title" : "potato"
}'
curl -XPOST "http://localhost:9200/syn/data/3" -d'
{
"title" : "tomato"
}'
curl -XPOST "http://localhost:9200/syn/data/4" -d'
{
"title" : "carrot"
}'
curl -XGET "http://localhost:9200/syn/data/_search" -d'
{
"query": {
"function_score" : {
"query" : {
"match": {
"title": "vegetable"
}
},
"script_score" : {
"script" : "boosted_syn",
"params" : {
"field" : "title",
"term" : "vegetable"
}
},
"boost_mode" : "replace"
}
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.