Skip to content

Instantly share code, notes, and snippets.

@Alino
Created September 24, 2015 08:01
Show Gist options
  • Save Alino/4f7a80ee63012275605e to your computer and use it in GitHub Desktop.
Save Alino/4f7a80ee63012275605e to your computer and use it in GitHub Desktop.
How to filter out elements from an array that doesn’t match the query?
POST /products
{
"settings": {
"analysis": {
"filter": {
"nGram_filter": {
"type": "nGram",
"min_gram": 2,
"max_gram": 20,
"token_chars": [
"letter",
"digit",
"punctuation",
"symbol"
]
}
},
"analyzer": {
"nGram_analyzer": {
"type": "custom",
"tokenizer": "whitespace",
"filter": [
"lowercase",
"asciifolding",
"nGram_filter"
]
}
}
}
}
}
POST /products/paramSuggestions/_mapping
{
"properties": {
"productName": {
"type": "string"
},
"params": {
"properties": {
"paramName": {
"type": "string",
"analyzer": "nGram_analyzer"
},
"value": {
"type": "string",
"analyzer": "nGram_analyzer"
}
}
}
}
}
POST /products/paramSuggestions/1
{
"productName": "iphone 6",
"params": [
{
"paramName": "color",
"value": "white"
},
{
"paramName": "capacity",
"value": "32GB"
}
]
}
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 0.33217794,
"hits": [
{
"_index": "products",
"_type": "paramSuggestions",
"_id": "1",
"_score": 0.33217794,
"_source": {
"productName": "iphone 6",
"params": [
{
"paramName": "color",
"value": "white"
},
{
"paramName": "capacity",
"value": "32GB"
}
]
}
}
]
}
}
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 0.33217794,
"hits": [
{
"_index": "products",
"_type": "paramSuggestions",
"_id": "1",
"_score": 0.33217794,
"_source": {
"productName": "iphone 6",
"params": [
{
"paramName": "color",
"value": "white"
},
]
}
}
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment