Skip to content

Instantly share code, notes, and snippets.

@clintongormley
Created May 23, 2014 10:04
Show Gist options
  • Save clintongormley/1da07e7576f38713e5c5 to your computer and use it in GitHub Desktop.
Save clintongormley/1da07e7576f38713e5c5 to your computer and use it in GitHub Desktop.
Only match if it matches all the tokens in a field
DELETE /_all
PUT /t
{
"mappings": {
"test": {
"properties": {
"text": {
"type": "string",
"analyzer": "english",
"fields": {
"count": {
"type": "token_count",
"analyzer": "english"
}
}
}
}
}
}
}
PUT /t/test/1
{
"text": "baseball bats"
}
GET /t/_analyze?field=text&text=baseball glove and hat
GET /t/test/_search
{
"query": {
"match": {
"text": "baseball glove and hat"
}
},
"rescore": {
"window_size": 1000,
"query": {
"score_mode": "multiply",
"rescore_query": {
"function_score": {
"query": {
"function_score": {
"score_mode": "sum",
"boost_mode": "replace",
"functions": [
{
"filter": {
"match_all": {}
},
"boost_factor": 0
},
{
"filter": {
"term": {
"text": "basebal",
"_cache": false
}
},
"boost_factor": 1
},
{
"filter": {
"term": {
"text": "glove",
"_cache": false
}
},
"boost_factor": 1
},
{
"filter": {
"term": {
"text": "bat",
"_cache": false
}
},
"boost_factor": 1
}
]
}
},
"boost_mode": "replace",
"score_mode": "first",
"functions": [
{
"filter": {
"match_all": {}
},
"script_score": {
"script": "return (_score < doc['text.count'].value) ? 0: 1"
}
}
]
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment