念念熙
2018-04-06 21:52
老师,为什么我搜索name的值为大写开头的时候,返回的是这样的结果呢?
GET accounts/person/_search { "query": { "term": { "name": { "value": "John" } } } }
{ "took": 2, "timed_out": false, "_shards": { "total": 5, "successful": 5, "skipped": 0, "failed": 0 }, "hits": { "total": 0, "max_score": null, "hits": [] } }
把name的值改成小写开头的时候就能正确返回结果。
哦,你用的是term查询,是直接拿着这个term去匹配的,但是默认分词结果是小写的,所以会无法匹配,你用match就可以了
哦,你用的是term查询,是直接拿着这个term去匹配的,但是默认分词结果是小写的,所以会无法匹配,你用match就可以了
你的 mapping 设置是什么?具体文档是什么?
我通过命令GET /accounts/person/_mapping?pretty 查看mapping得到的是
{ "accounts": { "mappings": { "person": { "properties": { "job_description": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "lastname": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "name": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } } } } } } }
具体文档是不是指我建立的index和type的内容呢?
POST /accounts/person/1 { "name": "John", "lastname": "Doe", "job_description": "Systems administrator and Linux specialit" } POST /accounts/person/2 { "name": "Alfred", "lastname": "Way", "job_description": "teacher" }
Elastic Stack入门
32729 学习 · 76 问题
相似问题