Last active
August 29, 2015 14:07
-
-
Save nguyenhoaibao/fc832c1ca5f134be557a to your computer and use it in GitHub Desktop.
[elasticsearch] search co dau
This file contains 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
/** | |
* settings | |
* | |
*/ | |
curl -XPOST localhost:9200/lazada/ -d '{ | |
"settings": { | |
"number_of_shards": 1, | |
"analysis": { | |
"tokenizer" : { | |
"my_edge_ngram_tokenizer" : { | |
"type" : "edgeNGram", | |
"min_gram" : "2", | |
"max_gram" : "15", | |
"token_chars": [ "letter", "digit" ] | |
} | |
}, | |
"filter": { | |
"autocomplete_filter": { | |
"type": "edge_ngram", | |
"min_gram": 2, | |
"max_gram": 15 | |
}, | |
"my_ascii_folding": { | |
"type": "asciifolding", | |
"preserve_original": true | |
} | |
}, | |
"analyzer": { | |
"instant_search_analyzer": { | |
"type": "custom", | |
"tokenizer": "my_edge_ngram_tokenizer", | |
"filter": [ "lowercase", "my_ascii_folding" ] | |
}, | |
"search_analyzer": { | |
"type": "custom", | |
"tokenizer": "standard", | |
"filter": [ "lowercase", "my_ascii_folding" ] | |
} | |
} | |
} | |
} | |
}' | |
/** | |
* Test analyzer | |
* | |
*/ | |
curl -XGET localhost:9200/lazada/_analyze?analyzer=search_analyzer -d '{ | |
phượng hoàng hô | |
}' | |
/** | |
* create mapping | |
* | |
*/ | |
curl -XPUT 'localhost:9200/lazada/pd/_mapping' -d ' | |
{ | |
"properties": { | |
"name": { | |
"type": "string", | |
"index_analyzer": "instant_search_analyzer", | |
"search_analyzer": "search_analyzer" | |
} | |
} | |
}' | |
/** | |
* index some sample data | |
* | |
*/ | |
curl -XPOST 'localhost:9200/lazada/pd' -d '{ "name" : "mệnh phụng liêu tiên" }' | |
curl -XPOST 'localhost:9200/lazada/pd' -d '{ "name" : "harry potter và hội phượng hoàng" }' | |
curl -XPOST 'localhost:9200/lazada/pd' -d '{ "name" : "hỏa phụng liêu tiên" }' | |
curl -XPOST 'localhost:9200/lazada/pd' -d '{ "name" : "mệnh phượng hoàng" }' | |
curl -XPOST 'localhost:9200/lazada/pd' -d '{ "name" : "hè về phượng hồng đỏ rực" }' | |
curl -XPOST 'localhost:9200/lazada/pd' -d '{ "name" : "phi long và hỏa phụng" }' | |
curl -XPOST 'localhost:9200/lazada/pd' -d '{ "name" : "thức ăn cho bé hoàng phương" }' | |
curl -XPOST 'localhost:9200/lazada/pd' -d '{ "name" : "phố hoang vắng" }' | |
/** | |
* test search without minimum_should_match | |
* | |
*/ | |
curl -XGET 'localhost:9200/lazada/pd/_search?pretty' -d '{ | |
"query": { | |
"match": { | |
"name": "phượng h" | |
} | |
} | |
}' | |
/** | |
* test search with minimum_should_match | |
* | |
*/ | |
curl -XGET 'localhost:9200/lazada/pd/_search?pretty' -d '{ | |
"query": { | |
"match": { | |
"name": { | |
"query": "phượng hoàn", | |
"minimum_should_match": "75%" | |
} | |
} | |
}, | |
"highlight": { | |
"fields" : { | |
"name" : {} | |
} | |
} | |
}' | |
/** | |
* explain query | |
* | |
*/ | |
curl -XGET 'localhost:9200/lazada/pd/_validate/query?explain' -d '{ | |
"query": { | |
"match": { | |
"name": { | |
"query": "phượng hoàng hô" | |
} | |
} | |
} | |
}' | |
/** | |
* Update document | |
* | |
*/ | |
curl -XPOST localhost:9200/k54bd2bdbccec8def1a956141/fbPageTopic/267484169959021_933182530055845/_update -d '{ | |
"doc": { | |
"snippets": [ | |
{ | |
"sentiment": "1", | |
"labels": "54c264d54a832405140df990" | |
} | |
] | |
} | |
}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment