ES 搜索一(term)
POST /forum/article/_bulk {"index":{"_id":1}} { "articleID" : "XHDK-A-1293-#fJ3", "userID" : 1, "hidden": false, "postDate": "2017-01-01" } { "index": { "_id": 2 }} { "articleID" : "KDKE-B-9947-#kL5", "userID" : 1, "hidden": false, "postDate": "2017-01-02" } { "index": { "_id": 3 }} { "articleID" : "JODL-X-1937-#pV7", "userID" : 2, "hidden": false, "postDate": "2017-01-01" } { "index": { "_id": 4 }} { "articleID" : "QQPX-R-3956-#aD8", "userID" : 2, "hidden": true, "postDate": "2017-01-02" } GET /forum/_mapping/article GET /forum/article/_search { "query": { "constant_score": { "filter": { "term": { "userID": "2" } } } } } GET /forum/article/_search { "query": { "constant_score": { "filter": { "term": { "hidden": true } } } } } GET /forum/article/_search { "query": { "constant_score": { "filter": { "term": { "articleID.keyword": "QQPX-R-3956-#aD8" } } } } } GET /forum/article/_mapping DELETE /forum PUT /forum { "mappings": { "article":{ "properties": { "articleID":{ "type": "keyword" } } } } } PUT /forum { "mappings": { "article":{ "properties": { "articleID":{ "type": "keyword" } } } } } POST /forum/article/_bulk { "index": { "_id": 1 }} { "articleID" : "XHDK-A-1293-#fJ3", "userID" : 1, "hidden": false, "postDate": "2017-01-01" } { "index": { "_id": 2 }} { "articleID" : "KDKE-B-9947-#kL5", "userID" : 1, "hidden": false, "postDate": "2017-01-02" } { "index": { "_id": 3 }} { "articleID" : "JODL-X-1937-#pV7", "userID" : 2, "hidden": false, "postDate": "2017-01-01" } { "index": { "_id": 4 }} { "articleID" : "QQPX-R-3956-#aD8", "userID" : 2, "hidden": true, "postDate": "2017-01-02" } GET /forum/article/_search { "query": { "constant_score": { "filter": { "term": { "articleID": "JODL-X-1937-#pV7" } } } } }
term是搜字段完全匹配,在建立索引时,如果类型是text时,会被分词建立倒排索引,如果不想让字段倒排索引,可以设置其类型为keyword。
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步