Skip to content

Instantly share code, notes, and snippets.

@IvanShamatov
Created December 25, 2015 09:50
Show Gist options
  • Save IvanShamatov/06672743b9fbaf0286a2 to your computer and use it in GitHub Desktop.
Save IvanShamatov/06672743b9fbaf0286a2 to your computer and use it in GitHub Desktop.
POST /garagetools-development-products/_search
{
"query": {
"filtered": {
"query": {
"bool": {
"should": [
{
"prefix": {
"sku": {
"value": "n2010",
"boost": 6
}
}
},
{
"match": {
"sku": {
"query": "n2010",
"boost": 5
}
}
},
{
"match": {
"sku": {
"query": "n2010",
"boost": 4,
"fuzziness": 1
}
}
},
{
"match": {
"title": {
"query": "n2010",
"operator": "AND",
"max_expansions": 2,
"fuzziness": 1,
"boost": 3
}
}
},
{
"match": {
"name": {
"query": "n2010",
"operator": "AND",
"max_expansions": 2,
"fuzziness": 1,
"boost": 3
}
}
},
{
"match": {
"title": {
"query": "n2010",
"operator": "OR",
"max_expansions": 2,
"fuzziness": 1,
"boost": 2
}
}
},
{
"match": {
"name": {
"query": "n2010",
"operator": "OR",
"max_expansions": 2,
"fuzziness": 1,
"boost": 2
}
}
},
{
"query_string": {
"default_field": "description",
"query": "n2010"
}
}
]
}
},
"filter": [
{
"nested": {
"path": "stocks",
"query": {
"bool": {
"must": [
{
"terms": {
"stocks.warehouse_id": [
"53efb61173727668085cc800",
"53efb61173727668085ec800"
]
}
}
]
}
}
}
},
{
"nested": {
"path": "prices",
"query": {
"term": {
"prices.price_type_id": "53efb61073727668080bc800"
}
}
}
}
]
}
},
"track_scores": true,
"sort": {
"_script": {
"script": "(!!doc['stocks_available'].intersect(availables)) ? _score : -1/(_score*1.0)",
"lang": "groovy",
"type": "number",
"params": {
"availables": [
"53efb61173727668085cc800",
"53efb61173727668085ec800"
]
},
"order": "desc"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment