2016-12-13 49 views
1

我目前使用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文件。

这是什么原因造成的?

+1

这是因为'contactMethods'是一个'嵌套'字段和嵌套字段[不能通过'query_string'查询](https://github.com/elastic/elasticsearch/issues/16551)查询。上面的例子查询“ – Val

+0

”地址“”字段。 – Leo

回答