2016-08-18 8 views
0

ステップ1:http://localhost:9200/shop/_mapping/cloth弾性クエリネストされたクエリ

HTTP/1.1 200 OK のContent-Type:mapping.json以下

{ 
    "cloth" : 
    { 
     "properties" : 
     { 
      "name" : { "type" : "string", "index" : "analyzed" }, 
      "variation" : 
      { 
      "type" : "nested", 
      "properties" : 
      { 
       "size" : 
       { 
        "type" : "string", "index" : "not_analyzed" 
       }, 
       "color" : 
       { 
        "type" : "string", "index" : "not_analyzed" 
       } 
      } 
     } 
    } 
    } 
} 

GETと弾性検索 http://localhost:9200/shopにインデックスを作成し

:application/json; charset = UTF-8 コンテンツの長さ:518

{"ショップ":{"マッピング":{"プロパティ" {{"布":{"プロパティ":{"プロパティ" {"タイプ": "文字列"}}} "バリエーション":{"プロパティ" {"型": "" {"型": "型": "型":{"型": " "type": "string"}}}}、 "type": "type": "type": "type": "string" {"type": "string"}、 "variation":{"プロパティ":{"color":{"type": "string"} " : "文字列"}、 "サイズ":{ "タイプ": "文字列"}}}}}}}}

ステップ2:

はdata.j下記でデータを挿入します息子 http://localhost:9200/shop/cloth/?_create

{ 
"name" : "Test shirt", 
"variation" : [ 
{ "size" : "XXL", "color" : "red" }, 
{ "size" : "XL", "color" : "black" } 
] 
} 

は、ステップ3:

HTTP/1.1 400不正な要求を踏襲している与えられたquery.jsonエラー以下

http://localhost:9200/shop/cloth/_search

{ 
"query" : { 
"nested" : { 
"path" : "variation", 
"query" : { 
"bool" : { 
"must" : [ 
{ "term" : { "variation.size" : "XXL" } }, 
{ "term" : { "variation.color" : "black" } } 
] 
} 
} 
} 
} 
} 

で検索しようとしました コンテンツタイプ:application/json;文字セット= UTF-8 のContent-Length:519

{"error":{"root_cause":[{"type":"query_parsing_exception","reason":"[nested] nested object under path [variation] is not of nested type","index":"shop","line":4,"col":1}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"shop","node":"6U9SA_SDRJKfw1bRxwH8ig","reason":{"type":"query_parsing_exception","reason":"[nested] nested object under path [variation] is not of nested type","index":"shop","line":4,"col":1}}]},"status":400} 

ネストされたクエリで検索する方法は何ですか?検索クラスタにマッピングファイルを読み込むための適切な方法はありますか?

+0

あなたはあなたの質問では、フォームを取得し、出力を更新することができます 'カール-XGETはlocalhost:9200 /ショップ/ _mapping/cloth'を? – Val

+0

mapping.jsonの内容でPOSTとして使用しているように、マッピングを挿入する方法 –

+0

私の悪い、申し訳ありませんが、私の上記のコメントをもう一度チェックしてください。 – Val

答えて

1

clothマッピングを使用してインデックスを正しく作成していないと思います。このようにそれを実行します。

# delete your index first 
curl -XDELETE localhost:9200/shop 

# create it properly 
curl -XPUT localhost:9200/shop -d '{ 
    "mappings": { 
    "cloth": { 
     "properties": { 
     "name": { 
      "type": "string", 
      "index": "analyzed" 
     }, 
     "variation": { 
      "type": "nested", 
      "properties": { 
      "size": { 
       "type": "string", 
       "index": "not_analyzed" 
      }, 
      "color": { 
       "type": "string", 
       "index": "not_analyzed" 
      } 
      } 
     } 
     } 
    } 
    } 
}' 
+0

これはあなたのためにできましたか? – Val

0
{ 
    "query" : { 
     "nested" : { 
      "path" : "cloth.variation", 
      "query" : { 
       "bool" : { 
        "must" : [ 
         { "term" : { "cloth.variation.size" : "XXL" } }, 
         { "term" : { "cloth.variation.color" : "black" } } 
        ] 
       } 
      } 
     } 
    } 
} 
+0

説明を追加する必要があります。 – Sam