10年 Java程序员,硬核人生!勇往直前,永不退缩!

欢迎围观我的git:https://github.com/R1310328554/spring_security_learn 寻找志同道合的有志于研究技术的朋友,关注本人微信公众号: 觉醒的码农,或Q群 165874185

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

准备:

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, 查询结果是一样的。

posted on 2017-05-24 17:03  CanntBelieve  阅读(301)  评论(0编辑  收藏  举报