嘿~ 今天天气不错嘛

字段折叠错误

Elasticsearch | 作者 dlliwei | 发布于2018年01月19日 | 阅读数:1855

数据如下:
index1/type1
{"id":1,  "enName" : "2,6-Pyridinedicarbonyl"}
{"id":2,  "enName" : "2,6-Pyridinedicarbonyl"}
{"id":3,  "enName" : "2,6-Pyridinedicarbonyl"}
index1/type2
{"id":1, "compoundId": 19, "enSynonyms" : "2,6-Pyridinedicarbonyl"}
{"id":2, "compoundId": 20, "enSynonyms" : "2,6-Pyridinedicarbonyl aa"}
{"id":3, "compoundId": 20, "enSynonyms" : "2,6-Pyridinedicarbonyl bb"}
{"id":4, "compoundId": 20, "enSynonyms" : "2,6-Pyridinedicarbonyl cc"}
 
关键字搜索“2,6-Pyridinedicarbonyl”默认会返回以上所有数据7条:
{
    "query": {
      "bool" : {
        "should" : [
            { "match_phrase" : {"enSynonyms" : "2,6-Pyridinedicarbonyl"} },
           { "match_phrase" : {"enName" : "2,6-Pyridinedicarbonyl"} }
        ]
      }
    }
}
现在我希望type2中的数据按照compoundId折叠:
{
    "query": {
      "bool" : {
        "should" : [
            { "match_phrase" : {"enSynonyms" : "2,6-Pyridinedicarbonyl"} },
           { "match_phrase" : {"enName" : "2,6-Pyridinedicarbonyl"} }
        ]
      }
    },
   "collapse": {"field": "compoundId" }
}
希望返回如下数据:
index1/type1
{"id":1,  "enName" : "2,6-Pyridinedicarbonyl"}
{"id":2,  "enName" : "2,6-Pyridinedicarbonyl"}
{"id":3,  "enName" : "2,6-Pyridinedicarbonyl"}
index1/type2
{"id":1, "compoundId": 19, "enSynonyms" : "2,6-Pyridinedicarbonyl"}
{"id":2, "compoundId": 20, "enSynonyms" : "2,6-Pyridinedicarbonyl aa"}
 
但是实际上返回的是如下结果(type1的数据也折叠了):
index1/type1
{"id":1,  "enName" : "2,6-Pyridinedicarbonyl"}
index1/type2
{"id":1, "compoundId": 19, "enSynonyms" : "2,6-Pyridinedicarbonyl"}
{"id":2, "compoundId": 20, "enSynonyms" : "2,6-Pyridinedicarbonyl aa"}
 
谁知道怎么解决?
已邀请:

要回复问题请先登录注册