数组中的 Elastic Search "must"
Elastic Search "must" in array
我是 Elastic Search 的新手。
我已经在 elasticsearch 中索引了下一个对象:
"doc": [
{
"partes": [
{
"algo": [
{
"Category": "Therapeutic or Preventive Procedure",
"Neg": "false",
"CandidatePreferred": "Obstetric Surgical Procedures",
"CandidateScore": "1000",
"CandidateMatched": "Obstetric Surgical",
"Phrase": "OBSTETRIC SURGICAL",
"CUI": "C0038906"
}
]
}
]
},
{
"partes": [
{
"algo": [
{
"Category": "Intellectual Product",
"Neg": "false",
"CandidatePreferred": "Given name",
"CandidateScore": "790",
"CandidateMatched": "given",
"Phrase": "given of discharge",
"CUI": "C3244317"
},
{
"Category": "Body Substance",
"Neg": "false",
"CandidatePreferred": "Discharge, body substance",
"CandidateScore": "790",
"CandidateMatched": "Discharge",
"Phrase": "given of discharge",
"CUI": "C2926602"
}
]
},
{
"algo": [
{
"Category": "Health Care Activity",
"Neg": "false",
"CandidatePreferred": "Patient Discharge",
"CandidateScore": "790",
"CandidateMatched": "Discharge",
"Phrase": "given of discharge",
"CUI": "C0030685"
},
{
"Category": "Intellectual Product",
"Neg": "false",
"CandidatePreferred": "Given name",
"CandidateScore": "790",
"CandidateMatched": "given",
"Phrase": "given of discharge",
"CUI": "C3244317"
}
]
}
]
}
]
}
}
我的 objective 是获取我在同一元素中有两个 CUI 的元素 algo,即有一个 algo 在 doc 中有两个 CUI:C3244317 和 C2926602.
我正在尝试进行下一次搜索:
{
"query": {
"nested": {
"path": "doc",
"query": {
"nested":{
"path":"doc.partes",
"query": {
"nested": {
"path":"doc.partes.algo",
"query": {
"bool": {
"must": [
{ "term": { "doc.partes.algo.CUI": "C3244317" }},
{ "term": { "doc.partes.algo.CUI": "C2926602" }}
]
}
}
}
}
}
}
}
}
}
但是我还没有得到任何结果:
{
"took": 5,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 0,
"max_score": null,
"hits": []
}
}
我得到的结果是 should 而不是 must,但这不是我一直在寻找的行为。
默认 standard analyzer 删除大部分标点符号,将文本分解为单个单词,并将它们小写。
所以 C3244317 可能被索引为 c3244317,即小写 'c'。
您不需要这么大的查询。这应该可以正常工作:
{
"query":{
"bool":{
"must":[
{
"term":{
"doc.partes.algo.CUI":"c3244317"
}
},
{
"term":{
"doc.partes.algo.CUI":"c2926602"
}
}
]
}
}
}
我是 Elastic Search 的新手。
我已经在 elasticsearch 中索引了下一个对象:
"doc": [
{
"partes": [
{
"algo": [
{
"Category": "Therapeutic or Preventive Procedure",
"Neg": "false",
"CandidatePreferred": "Obstetric Surgical Procedures",
"CandidateScore": "1000",
"CandidateMatched": "Obstetric Surgical",
"Phrase": "OBSTETRIC SURGICAL",
"CUI": "C0038906"
}
]
}
]
},
{
"partes": [
{
"algo": [
{
"Category": "Intellectual Product",
"Neg": "false",
"CandidatePreferred": "Given name",
"CandidateScore": "790",
"CandidateMatched": "given",
"Phrase": "given of discharge",
"CUI": "C3244317"
},
{
"Category": "Body Substance",
"Neg": "false",
"CandidatePreferred": "Discharge, body substance",
"CandidateScore": "790",
"CandidateMatched": "Discharge",
"Phrase": "given of discharge",
"CUI": "C2926602"
}
]
},
{
"algo": [
{
"Category": "Health Care Activity",
"Neg": "false",
"CandidatePreferred": "Patient Discharge",
"CandidateScore": "790",
"CandidateMatched": "Discharge",
"Phrase": "given of discharge",
"CUI": "C0030685"
},
{
"Category": "Intellectual Product",
"Neg": "false",
"CandidatePreferred": "Given name",
"CandidateScore": "790",
"CandidateMatched": "given",
"Phrase": "given of discharge",
"CUI": "C3244317"
}
]
}
]
}
]
}
}
我的 objective 是获取我在同一元素中有两个 CUI 的元素 algo,即有一个 algo 在 doc 中有两个 CUI:C3244317 和 C2926602.
我正在尝试进行下一次搜索:
{
"query": {
"nested": {
"path": "doc",
"query": {
"nested":{
"path":"doc.partes",
"query": {
"nested": {
"path":"doc.partes.algo",
"query": {
"bool": {
"must": [
{ "term": { "doc.partes.algo.CUI": "C3244317" }},
{ "term": { "doc.partes.algo.CUI": "C2926602" }}
]
}
}
}
}
}
}
}
}
}
但是我还没有得到任何结果:
{
"took": 5,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 0,
"max_score": null,
"hits": []
}
}
我得到的结果是 should 而不是 must,但这不是我一直在寻找的行为。
默认 standard analyzer 删除大部分标点符号,将文本分解为单个单词,并将它们小写。
所以 C3244317 可能被索引为 c3244317,即小写 'c'。
您不需要这么大的查询。这应该可以正常工作:
{
"query":{
"bool":{
"must":[
{
"term":{
"doc.partes.algo.CUI":"c3244317"
}
},
{
"term":{
"doc.partes.algo.CUI":"c2926602"
}
}
]
}
}
}