2016-08-18 21 views
0

Schritt 1: http://localhost:9200/shop/_mapping/clothElastic Abfrage Verschachtelte Abfrage

HTTP/1.1 200 OK Content-Type:

einen Index für Elasticsearch http://localhost:9200/shop mit unter 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 Erstellt : Anwendung/JSON; charset = UTF-8 Content-Length: 518

{ "shop": { "Mappings": { "Tuch": { "Eigenschaften": { "Tuch": { "Eigenschaften": { "Eigenschaften": {"Eigenschaften": {"Name": {"Eigenschaften": {"Index": {"Typ": "Zeichenkette"}, "Typ": {"Typ": "Zeichenkette"}}}, "Variation": {"Eigenschaften": {"Eigenschaften": {"Eigenschaften": {"Farbe": {"Eigenschaften": {"Index": {"Typ": "Zeichenkette"}, "Typ": {"Typ": "" String "}}}," Größe ": {" Eigenschaften ": {" Index ": {" Typ ":" String "}," Typ ": {" Typ ":" String "}}}}," Typ ": {" type ":" string "}}}}}}}," name ": {" type ":" string "}," variation ": {" Eigenschaften ": {" color ": {" type " : "string"}, "Größe": { "type": "string"}}}}}}}}

Schritt 2:

die Daten eingefügt mit unten angegebenen data.j Sohn http://localhost:9200/shop/cloth/?_create

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

Schritt 3:

mit bestimmten query.json

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

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

Unten Fehler folgt

HTTP/1.1 400 Bad Request Inhaltstyp: application/json; charset = 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} 

Was ist der Weg zu suchen, mit Abfragen verschachtelt? Gibt es eine geeignete Methode zum Laden der Zuordnungsdatei in den Such-Cluster?

+0

Können Sie Ihre Frage mit dem Ausgang Sie Formular get update 'curl -XGET localhost: 9200/shop/_mapping/cloth'? – Val

+0

Wie wir das Mapping einfügen können, wie es als POST mit Mapping.json Inhalt –

+0

mein schlechtes tut, tut mir leid, bitte überprüfen Sie meine obigen Kommentar erneut. – Val

Antwort

1

Ich denke, Sie erstellen nicht ordnungsgemäß Ihren Index mit der cloth Zuordnung. Tun Sie es auf diese Weise:

# 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

Hat dies für Sie funktioniert? – Val

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

Sie sollten eine Erklärung hinzufügen. – Sam