准备:
1 创建索引:
PUT my_index
PUT my_index2
2 先做好映射:
PUT /my_index/*/_mapping
{
"properties": {
"addTime": {
"type": "date",
"format": "strict_date_optional_time||epoch_millis"
},
"content": {
"type": "string",
"analyzer": "ik"
},
"creatorId": {
"type": "long"
},
"fileName": {
"type": "string",
"analyzer": "ik"
},
"filePath": {
"type": "string",
"index": "not_analyzed"
},
"id": {
"type": "long"
},
"lastModified": {
"type": "long"
},
"revisionCount": {
"type": "long"
},
"size": {
"type": "long"
}
}
}
3 准备数据:
PUT /my_index2/aa/1
{
"fileName": "中华人民共和国",
"content": "从重新开始hello jetty"
}
PUT /my_index/aa/1
{
"fileName": "中华人民共和国",
"content": "从重新开始hello jetty"
}
GET /my_index2/_mapping
测试:
GET /my_index/aa/_search
{
"query": {
"term": {
"fileName": "人民"
}
}
}
GET /my_index2/aa/_search
{
"query": {
"term": {
"fileName": "人民"
}
}
}
说明:
通过下面的是测试不出来的, 因为, 她已经制定了分词器为 ik,
POST /my_index/_analyze?pretty=true
{
"text": "我是中国人"
}
使用query查询的时候, 查询器必须是 term, 如果是match, 查询结果是一样的。