构建Shingles模版并指定相应字段使用该属性
PUT /my_index
{
"settings" : {
"index" : {
"analysis": {
"filter": {
"my_shingle_filter": {
"type": "shingle",
"min_shingle_size": 2,
"max_shingle_size": 2,
"output_unigrams": false
}
},
"analyzer": {
"my_shingle_analyzer": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"my_shingle_filter"
]
}
}
},
"number_of_replicas" : "1"
}
},
"mappings" : {
"properties" : {
"title" : {
"type": "text",
"fields": {
"shingles": {
"type": "text",
"analyzer": "my_shingle_analyzer"
}
}
}
}
}
}
批量插入测试数据
POST /my_index/_bulk
{
"index": {
"_id": 1 }}
{
"title": "Sue ate the alligator" }
{
"index": {
"_id": 2 }}
{
"title": "The alligator ate Sue" }
{
"index": {
"_id": 3 }}
{
"title": "Sue never goes anywhere without her alligator skin purse" }
普通查询
GET /my_index/_search
{
"query": {
"match": {
"title": "the hungry alligator ate sue"
}
}
}
相关性查询
GET /my_index/_search
{
"query": {
"match": {
"title.shingles": "the hungry alligator ate sue"
}
}
}