我目前使用ES版本2.3.5。我有一個由springboot REST項目自動創建的ES映射:Elasticsearch問題搜索嵌套數組對象不工作
{
"customer" : {
"aliases" : { },
"mappings" : {
"customer" : {
"properties" : {
"addresses" : {
"type" : "nested",
"include_in_parent" : true,
"properties" : {
"address1" : {
"type" : "string"
},
"address2" : {
"type" : "string"
},
"address3" : {
"type" : "string"
},
"country" : {
"type" : "string"
},
"id" : {
"type" : "string"
},
"latitude" : {
"type" : "double"
},
"longitude" : {
"type" : "double"
},
"postcode" : {
"type" : "string"
},
"state" : {
"type" : "string"
},
"town" : {
"type" : "string"
},
"unit" : {
"type" : "string"
}
}
},
"companyNumber" : {
"type" : "string"
},
"contactMethods" : {
"type" : "nested",
"include_in_parent" : true,
"properties" : {
"type" : {
"type" : "string"
},
"description" : {
"type" : "string"
},
"value" : {
"type" : "string"
}
}
},
"contacts" : {
"properties" : {
"contactType" : {
"type" : "string"
},
"detail" : {
"type" : "string"
}
}
},
"id" : {
"type" : "string",
"index" : "not_analyzed"
},
"name" : {
"type" : "string"
},
"parent" : {
"type" : "nested",
"include_in_parent" : true,
"properties" : {
"id" : {
"type" : "string"
},
"name" : {
"type" : "string"
},
"type" : {
"type" : "string"
}
}
},
"status" : {
"type" : "string"
},
"timeCreated" : {
"type" : "date",
"format" : "strict_date_optional_time||epoch_millis"
},
"timeUpdated" : {
"type" : "date",
"format" : "strict_date_optional_time||epoch_millis"
},
"type" : {
"type" : "string"
}
}
}
}
}
}
搜索服務類構建查詢。例如,通過發出查詢的地址欄「addresses.address1:昆」在端點上,查詢將是:
{
"bool" : {
"should" : {
"query_string" : {
"query" : "(addresses.address1:Queensland)",
"fields" : [ "type", "name", "companyNumber", "status", "parent.id", "parent.name", "parent.type", "addresses.id", "addresses.unit", "addresses.address1", "addresses.address2", "addresses.address3", "addresses.town", "addresses.state", "addresses.postcode", "addresses.country", "contactMethods.type", "contactMethods.value", "contactMethods.description" ],
"default_operator" : "or",
"analyze_wildcard" : true,
"lenient" : true
}
}
}
}
返回正確的文件。例如響應:
{
"page": 1,
"pageSize": 10,
"totalPages": 1,
"totalElements": 1,
"data": [
{
"id": "1",
"timeCreated": "2016-09-01T14:52:44Z",
"timeUpdated": "2016-09-01T15:25:46Z",
"type": "BUSINESS",
"name": "John Doe",
"companyNumber": "1000000002",
"status": "PENDING",
"addresses": [
{
"id": "1",
"address1": "Queensland Street",
"address2": "Casa Fuego",
"town": "New Kingslanding",
"state": "QA",
"postcode": "2222",
"country": "AU",
"longitude": 151.080739,
"latitude": -33.770029
}
],
"contactMethods": [
{
"type": "MOBILE",
"value": ""
},
{
"type": "EMAIL",
"value": "[email protected]"
}
]
}
]
}
但是,如果我通過查詢contactMethods場 「contactMethods.type:EMAIL」 或 「contactMethods.type:MOBILE」,甚至 「contactMethods.type:*」 甚至小寫的 「電子郵件」 和「移動「返回空文件或0文件。
這是什麼原因造成的?
這是因爲'contactMethods'是一個'嵌套'字段和嵌套字段[不能通過'query_string'查詢](https://github.com/elastic/elasticsearch/issues/16551)查詢。上面的例子查詢「 – Val
」地址「」字段。 – Leo