2016-07-18 15 views
1

マイインデックス・メタデータ:弾性検索:配列内の検索結果を制限する

{ 
    "never": { 
     "aliases": {}, 
     "mappings": { 
     "userDetails": { 
      "properties": { 
       "Residence_address": { 
        "type": "nested", 
        "include_in_parent": true, 
        "properties": { 
        "Address_type": { 
         "type": "string", 
         "analyzer": "standard" 
        }, 
        "Pincode": { 
         "type": "string", 
         "analyzer": "standard" 
        }, 
        "address": { 
         "type": "string", 
         "analyzer": "standard" 
        } 
        } 
       } 
      } 
     } 
     }, 
     "settings": { 
     "index": { 
      "creation_date": "1468850158519", 
      "number_of_shards": "5", 
      "number_of_replicas": "1", 
      "version": { 
       "created": "1060099" 
      }, 
      "uuid": "v2njuC2-QwSau4DiwzfQ-g" 
     } 
     }, 
     "warmers": {} 
    } 
} 

マイセッティング:

POST never 

{ 
    "settings": { 
     "number_of_shards" : 5, 
     "analysis": { 
     "analyzer": { 
      "standard": { 
       "tokenizer": "keyword", 
       "filter" : ["lowercase","reverse"] 
      } 
     } 
     } 
    } 
} 

マイデータ:

{ 
    "took": 1, 
    "timed_out": false, 
    "_shards": { 
     "total": 5, 
     "successful": 5, 
     "failed": 0 
    }, 
    "hits": { 
     "total": 1, 
     "max_score": 0.375, 
     "hits": [ 
     { 
      "_index": "never", 
      "_type": "userDetails", 
      "_id": "1", 
      "_score": 0.375, 
      "_source": { 
       "Residence_address": [ 
        { 
        "address": "Omega Residency", 
        "Address_type": "Owned", 
        "Pincode": "500004" 
        }, 
        { 
        "address": "Collage of Engineering", 
        "Address_type": "Rented", 
        "Pincode": "411005" 
        } 
       ] 
      } 
     } 
     ] 
    } 
} 

マイクエリ:

POST /never/_search?pretty 
{ 
    "query": { 
     "match": { 
       "Residence_address.address": "Omega" 
      } 
     } 
     } 

マイ結果:

{ 
    "took": 1, 
    "timed_out": false, 
    "_shards": { 
     "total": 5, 
     "successful": 5, 
     "failed": 0 
    }, 
    "hits": { 
     "total": 1, 
     "max_score": 0.375, 
     "hits": [ 
     { 
      "_index": "never", 
      "_type": "userDetails", 
      "_id": "1", 
      "_score": 0.375, 
      "_source": { 
       "Residence_address": [ 
        { 
        "address": "Omega Residency", 
        "Address_type": "Owned", 
        "Pincode": "500004" 
        }, 
        { 
        "address": "Collage of Engineering", 
        "Address_type": "Rented", 
        "Pincode": "411005" 
        } 
       ] 
      } 
     } 
     ] 
    } 
} 

物体のみ含むアドレスへの私の結果を制限する方法はあり=オメガレジデンシーとされていない他のオブジェクト持つアドレス=コラージュエンジニアリングの?

答えて

1

nestedクエリとinner_hitsでのみ実行できます。あなたはinclude_in_parent: trueを持っていて、nestedというクエリを使用していないことがわかります。

GET /never/_search?pretty 
{ 
    "_source": false, 
    "query": { 
    "nested": { 
     "path": "Residence_address", 
     "query": { 
     "match": { 
      "Residence_address.address": "Omega Residency" 
     } 
     }, 
     "inner_hits" : {} 
    } 
    } 
} 
+0

おかげ@Andreiステファン:あなたが唯一のマッチネストされたオブジェクトを取得したい場合は、inner_hitsnestedからのクエリを使用する必要があるだろう。できます。 – Bond

関連する問題