Skip to content

Instantly share code, notes, and snippets.

@yanglikun
Last active June 27, 2017 02:03
Show Gist options
  • Save yanglikun/45f2bf836af35dfb63ac8e48b3e8caaf to your computer and use it in GitHub Desktop.
Save yanglikun/45f2bf836af35dfb63ac8e48b3e8caaf to your computer and use it in GitHub Desktop.
es-分析器
POST /analyzer_index
{
"settings": {
"index": {
"analysis": {
"analyzer":{
"myCustomAnalyzer":{
"type":"custom",
"tokenizer":"myCustomTokenizer",
"filter":["myCustomFilter1","myCustomFilter2"],
"char_filter":["myCustomCharFilter"]
}
},
"tokenizer":{
"myCustomTokenizer":{
"type":"letter"
}
},
"filter":{
"myCustomFilter1":{
"type":"lowercase"
},
"myCustomFilter2":{
"type":"kstem"
}
},
"char_filter":{
"myCustomCharFilter":{
"type":"mapping",
"mappings":["jingdong=>jd","360buy=>jd"]
}
}
}
}
},
"mappings":{
"analyzer_type":{
"properties":{
"description":{
"type":"string",
"analyzer":"myCustomAnalyzer"
}
}
}
}
}
POST /analyzer_index
{
"settings": {
"index": {
"analysis": {
"analyzer":{
"myCustomAnalyzer":{
"type":"custom",
"tokenizer":"myCustomTokenizer",
"filter":["myCustomFilter2"],
"char_filter":["myCustomCharFilter"]
}
},
"tokenizer":{
"myCustomTokenizer":{
"type":"letter"
}
},
"filter":{
"myCustomFilter2":{
"type":"kstem"
}
},
"char_filter":{
"myCustomCharFilter":{
"type":"mapping",
"mappings":["jingdong=>jd","360buy=>jd"]
}
}
}
}
},
"mappings":{
"analyzer_type":{
"properties":{
"description":{
"type":"string",
"analyzer":"myCustomAnalyzer"
}
}
}
}
}
GET analyzer_index/_mapping
DELETE /analyzer_index
POST /analyzer_index/analyzer_type/_bulk
{"index":{"_id":"1"}}
{"description":"go shopping go 360buy"}
{"index":{"_id":"2"}}
{"description":"Go shopping go jingdong"}
{"index":{"_id":"3"}}
{"description":"go shopping go jd"}
{"index":{"_id":"4"}}
{"description":"go shopping"}
GET /analyzer_index/analyzer_type/_search
GET /analyzer_index/analyzer_type/_search
{
"query": {
"match": {
"description": {
"query":"360buy",
"analyzer": "keyword"
}
}
}
}
GET /analyzer_index/analyzer_type/_search
{
"query": {
"match": {
"description": {
"query":"360buy"
}
}
}
}
##analyze text to token
#based on custom
GET _analyze
{
"analyzer":"standard",
"text":"go shopping for 360buy jd"
}
GET _analyze
{
"tokenizer":"whitespace",
"filters":["lowercase","reverse"],
"text":"share your experience with NoSql & big data technologies"
}
#based on a analyzer of index
GET /analyzer_index/_analyze
{
"analyzer":"myCustomAnalyzer",
"text":"go shopping go jd"
}
#based on a filed
GET /analyzer_index/_analyze
{
"field":"description",
"text":"go shopping go 360buy"
}
#retrive term of document with id
GET /analyzer_index/analyzer_type/1/_termvectors
{
"fields" : ["description"],
"offsets" : true,
"payloads" : true,
"positions" : true,
"term_statistics" : true,
"field_statistics" : true
}
#why a document did not match
POST /analyzer_index/analyzer_type/1/_explain
{
"query": {
"match": {
"description": "jd"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment