【发布时间】:2019-07-13 15:05:31
【问题描述】:
我有一个索引(名称:“index1”)指向 ElasticSearch 中的多个文档。
文档的格式(json)是 -
{
"_index": "index1",
"_type": "someType",
"_id": "randomIDBlahBlah",
"_source": {
"version": "2018",
"fields": [
{
"field": "A.B",
"lineNumber": 1
},
{
"field": "C.D",
"lineNumber": 2
},
{
"field": "A.E",
"lineNumber": 3
}]
},
"fields": {
"created": [
"2017-01-19T20:11:07.977Z"
]
},
"sort": [
2324343
]
}
这是映射 -
{
"index1": {
"mappings": {
"mapping": {
"properties": {
"branch": {
"type": "text"
},
"created": {
"type": "date"
},
"fields": {
"type": "nested",
"properties": {
"field": {
"type": "text"
},
"lineNumber": {
"type": "integer"
}
}
}
}
}
}
}
}
同样,该索引下有多个文档,格式相同,但字段数据不同。
现在,我正在尝试在特定字段(此处为 A.B)上执行下面提到的弹性搜索,它为我提供所有文档的所有结果,就好像它是对所有字段的搜索一样。
我只想查看特定字段的结果,而不是所有结果。
这是我的 ES 查询 -
POST index1/_search
{
"query": {
"bool": {
"must": [
{
"bool": {
"should": [
{
"nested": {
"path": "fields",
"query": {
"match_phrase": {
"fields.field": "A.B"
}
}
}
}
]
}
}
]
}
}
}
我在 ES 查询中哪里做错了?
【问题讨论】:
-
fields.field的数据类型是什么?或者,如果您可以将index1的映射添加到您的问题中,我会更容易理解。 -
fields.field 是字符串类型。我在问题中添加了 index1 的映射。
标签: elasticsearch