2016-12-13 6 views
1

現在、ESバージョン2.3.5を使用しています。 springboot RESTプロジェクトによって自動的に作成されるESマッピングがあります。ネストされた配列オブジェクトを検索する際のエラ探索問題が有効でない

{ 
    "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:モバイル"、あるいは "contactMethods.type:*" でも、小文字の "電子メール" と「モバイル空または0のドキュメントを返します。

この原因は何ですか?

+1

これは、 'contactMethods'が' nested'フィールドであり、ネストされたフィールド['query_string'クエリ(https://github.com/elastic/elasticsearch/issues/16551)でクエリできないためです。 – Val

+0

"アドレス"フィールドが上記の例として照会されました。 – Leo

答えて

0

ネストされたプロパティは、異なるドキュメントとしてインデックスされます。ネストされた演算子を使用する必要があります。 https://www.elastic.co/guide/en/elasticsearch/guide/current/nested-query.htmlを参照してください。

+1

あなたのリンクがある時点で404になる場合のための例を提供する必要があります。 – Val

+0

@Ricardo上記の例のように、アドレスもネストされていますが動作します。しかしcontactMethodsではそうではありません。 – Leo

関連する問題