我遇到一个简单的存在过滤器的问题。我想要实现的是,返回所有具有特定字段的文档。 以下是他为我的索引绘图 -
"book": {
"dynamic": "true",
"properties": {
"currencies": {
"dynamic": "true",
"properties": {
"bookChallenge000": {
"type": "long"
},
"achievements": {
"type": "long"
},
"bookChallenge001": {
"type": "long"
},
"giftsSent": {
"type": "long"
},
"stars": {
"type": "long"
},
"knightsDonated": {
"type": "long"
}
}
},
"level": {
"type": "long"
},
"description": {
"index_analyzer": "str_index_analyzer",
"search_analyzer": "str_search_analyzer",
"type": "string"
},
"additionalMaxMembers": {
"type": "long"
},
"name": {
"index_analyzer": "str_index_analyzer",
"search_analyzer": "str_search_analyzer",
"type": "string"
},
"lastUpdated": {
"type": "long"
},
"active": {
"type": "boolean"
},
"bookClubId": {
"type": "string"
},
"attributes": {
"dynamic": "true",
"properties": {
"level": {
"type": "long"
},
"description": {
"index_analyzer": "str_index_analyzer",
"search_analyzer": "str_search_analyzer",
"type": "string"
},
"additionalMaxMembers": {
"type": "long"
},
"name": {
"index_analyzer": "str_index_analyzer",
"search_analyzer": "str_search_analyzer",
"type": "string"
},
"lastUpdated": {
"type": "long"
},
"active": {
"type": "boolean"
},
"memberCount": {
"type": "long"
},
"inviteStatus": {
"type": "string"
}
}
},
"meta": {
"dynamic": "false",
"properties": {
"bookRewards": {
"dynamic": "false",
"type": "object"
},
"challenges": {
"dynamic": "false",
"type": "object"
},
"grantedRewardInfo": {
"dynamic": "false",
"type": "object"
},
"levelRequirement": {
"type": "long"
},
"membersData": {
"dynamic": "false",
"type": "object"
},
"language": {
"type": "string"
},
"conversations": {
"dynamic": "false",
"type": "object"
},
"bookGoals": {
"dynamic": "false",
"type": "object"
},
"banner": {
"type": "string"
}
}
},
"memberCount": {
"type": "long"
},
"inviteStatus": {
"type": "string"
},
"version": {
"type": "long"
}
}
}
这是我要搜索的文件 -
{
attributes: {
active: true,
additionalMaxMembers: 0,
description: "famous five",
inviteStatus: "OPEN",
lastUpdated: 1452119518547,
level: 1,
memberCount: 39,
name: "zero"
},
currencies: {
bookChallenge000: 74316,
bookChallenge001: 142580,
bookChallenge002: 165526,
achievements: 582,
giftsSent: 0,
knightsDonated: 161,
stars: 1104
},
meta: {
banner: "enidBlyton_17",
challenges: {
Event014_Challenge_A: {
Currency: "bookChallenge000",
finishtime: 20550267,
goalscore: 30240,
memberscores: {
37339561405: 10,
37349022668: 2000,
37432453846: 20,
37437075798: 0
},
playerCurrency: "UserChallenge000"
},
Event014_Challenge_B: {
Currency: "bookChallenge001",
finishtime: 20290830,
goalscore: 38003,
memberscores: {
37339561405: 20,
37349022668: 38,
37432453846: 590
},
playerCurrency: "UserChallenge000"
}
},
language: "en_US",
levelRequirement: 14,
membersData: {
37442021220: {
achievements: 9,
giftsSent: 0,
knightsDonated: 0,
playerLikes: 28,
stars: 20
},
37493332413: {
achievements: 4,
giftsSent: 0,
knightsDonated: 0,
playerLikes: 0,
stars: 20
}
}
},
active: true,
bookClubId: "6106890",
inviteStatus: "OPEN",
memberCount: 39,
additionalMaxMembers: 0,
lastUpdated: 1452119518547,
description: "famous five",
name: "zero",
level: 1
}
我的查询非常简单,我需要所有具有挑战性的文档。
curl -X'GET' localhost:9200/book_index/_search -d '{"filter": {"exists" : { "field" : "challenges" }}}'
但它没有返回任何文件,我有100个带有挑战信息的文件。 我尝试过meta.challenges,还有challenge.membersData,但它没有用。 虽然如果我直接查找横幅或语言字段,我会得到预期的结果,但不能获得对象类型字段。
如何获取所有带有challenge或membersData的文档?
请告知我错过了什么。
答案 0 :(得分:1)
这是您要查找的查询:
{
"query": {
"filtered": {
"filter": {
"bool": {
"should": [
{
"exists": {
"field": "meta.challenges"
}
},
{
"exists": {
"field": "meta.membersData"
}
}
]
}
}
}
}
}