我有一些带有一些嵌套字段的简历索引。我正在运行以下代码来获取具有Ruby技能和计算机教育的简历。
GET /resume/candidates/_search
{
"query": {
"nested" : {
"path" : "sections",
"query" : {
"bool" : {
"must": [
{"match": {"sections.skills": "Ruby"}}
],
"filter" : [
{ "term" : {"sections.education": "computer"} }
]
}
}
}
}
}
当我单独运行时,bool和过滤器查询会给出正确的结果。但是当我把它们组合起来时,它们没有结果。我的索引中有一份简历,其中包括技能ruby和受过教育的计算机。
或者,目前我将离开乐谱部分,并将两者置于以下相同的条件下:
GET /resume/candidates/_search
{
"query": {
"nested" : {
"path" : "sections",
"query" : {
"bool" : {
"must": [
{"match": {
"sections.skills": "Ruby"}},
{"match": {
"sections.education": "computer"}}
]
}
}
}
}
}
它仍然不会返回任何结果,但如果单独写,它会返回结果。有人可以帮忙吗?
答案 0 :(得分:0)
拥有你的映射会很高兴。顺便说一下,我尝试使用此代码创建您的场景,并且查询有效:
首先定义映射
PUT resume
{
"mappings": {
"candidates": {
"properties": {
"sections": {
"type": "nested",
"properties": {
"skills": {
"type": "text"
},
"education": {
"type": "keyword"
}
}
}
}
}
}
}
然后添加两个候选人:
PUT resume/candidates/1
{
"sections": [
{
"skills": "Ruby",
"education": "computer"
},
{
"skills": "elastic",
"education": "computer"
}
]
}
PUT resume/candidates/2
{
"sections": [
{
"skills": "kibana",
"education": "computer"
},
{
"skills": "elastic",
"education": "computer"
}
]
}
这是查询:
GET resume/candidates/_search
{
"query": {
"nested": {
"path": "sections",
"query": {
"bool": {
"must": [
{
"term": {
"sections.education": {
"value": "computer"
}
}
},
{
"match": {
"sections.skills": "Ruby"
}
}
]
}
}
}
}
}
它只返回第一个canidate:
{
"took": 11,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 0.87546873,
"hits": [
{
"_index": "resume",
"_type": "candidates",
"_id": "1",
"_score": 0.87546873,
"_source": {
"sections": [
{
"skills": "Ruby",
"education": "computer"
},
{
"skills": "elastic",
"education": "computer"
}
]
}
}
]
}
}