如何在 elasticsearch 中搜索嵌套属性
How to search nested properties in elasticsearch
我的一个弹性索引中有一组记录,我正在尝试通过邮递员执行搜索查询,我当前的查询看起来像这样,应该找到 2 个结果,但结果为零。有什么问题吗?
{
"query": {
"match": {
"vehicle.CAR_WHEEL_DESCRIPTION": "A1=BB=C2C=D35"
}
}
}
当前响应:
{
"took": 6,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 0,
"relation": "eq"
},
"max_score": null,
"hits": []
}
}
我试过这样做,但我不仅得到了完全匹配,还得到了其他一些,总共 12 条记录(应该是 2,完全匹配记录)
{
"query": {
"nested": {
"path": "vehicle",
"query": {
"bool": {
"must": [
{ "match": { "vehicle.CAR_WHEEL_DESCRIPTION":
"A1=BB=C2C=D35" } }
]
}
},
"score_mode": "avg"
}
}
}
这是我根据你的信息做的例子。
PUT teste
{
"mappings": {
"properties": {
"vehicle": {
"type": "nested",
"properties": {
"CAR_WHEEL_DESCRIPTION": {
"type": "text"
}
}
}
}
}
}
POST teste/_doc
{
"vehicle": {
"CAR_WHEEL_DESCRIPTION": "A1=BB=C2C=D35"
}
}
GET teste/_search
{
"query": {
"nested": {
"path": "vehicle",
"query": {
"match": {
"vehicle.CAR_WHEEL_DESCRIPTION": {
"query": "A1=BB=C2C=D35"
}
}
}
}
}
}
我的一个弹性索引中有一组记录,我正在尝试通过邮递员执行搜索查询,我当前的查询看起来像这样,应该找到 2 个结果,但结果为零。有什么问题吗?
{
"query": {
"match": {
"vehicle.CAR_WHEEL_DESCRIPTION": "A1=BB=C2C=D35"
}
}
}
当前响应:
{
"took": 6,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 0,
"relation": "eq"
},
"max_score": null,
"hits": []
}
}
我试过这样做,但我不仅得到了完全匹配,还得到了其他一些,总共 12 条记录(应该是 2,完全匹配记录)
{
"query": {
"nested": {
"path": "vehicle",
"query": {
"bool": {
"must": [
{ "match": { "vehicle.CAR_WHEEL_DESCRIPTION":
"A1=BB=C2C=D35" } }
]
}
},
"score_mode": "avg"
}
}
}
这是我根据你的信息做的例子。
PUT teste
{
"mappings": {
"properties": {
"vehicle": {
"type": "nested",
"properties": {
"CAR_WHEEL_DESCRIPTION": {
"type": "text"
}
}
}
}
}
}
POST teste/_doc
{
"vehicle": {
"CAR_WHEEL_DESCRIPTION": "A1=BB=C2C=D35"
}
}
GET teste/_search
{
"query": {
"nested": {
"path": "vehicle",
"query": {
"match": {
"vehicle.CAR_WHEEL_DESCRIPTION": {
"query": "A1=BB=C2C=D35"
}
}
}
}
}
}