2016-10-03 6 views
0

Ich versuche ElasticSearch zu bekommen, um an meiner Box zu arbeiten. Ich habe die folgende Abbildung:Abfrage DSL elasticsearch funktioniert nicht

{ 
    "sneakers" : { 
    "mappings" : { 
     "sneaker" : { 
     "properties" : { 
      "brand" : { 
      "type" : "nested", 
      "properties" : { 
       "id" : { 
       "type" : "integer", 
       "index" : "no" 
       }, 
       "title" : { 
       "type" : "string" 
       } 
      } 
      } 
     } 
     } 
    } 
    } 
} 

So habe ich einen ‚Turnschuh‘ Index mit einem ‚Sneaker‘ Typ, mit einer ‚Marke‘ Eigenschaft, die ein ‚id‘ und ‚title‘ hat.

Überprüfen, dass Turnschuhe existieren, laufen curl -XGET 'http://localhost:9200/sneakers/sneaker/1?pretty', die ich erhalten:

{ 
    "_index" : "sneakers", 
    "_type" : "sneaker", 
    "_id" : "1", 
    "_version" : 1, 
    "found" : true, 
    "_source" : { 
    "brand" : { 
     "id" : 1, 
     "title" : "Nike" 
    } 
    } 
} 

Nun runningcurl -XGET 'http://localhost:9200/sneakers/_search?q=brand.title=adidas&pretty' ich:

{ 
    "took" : 13, 
    "timed_out" : false, 
    "_shards" : { 
    "total" : 5, 
    "successful" : 5, 
    "failed" : 0 
    }, 
    "hits" : { 
    "total" : 1330, 
    "max_score" : 0.42719018, 
    "hits" : [ { 
     "_index" : "sneakers", 
     "_type" : "sneaker", 
     "_id" : "19116", 
     "_score" : 0.42719018, 
     "_source" : { 
     "brand" : { 
      "id" : 2, 
      "title" : "Adidas" 
     } 
     } 
    }, ... 
} 

Aber sobald Ich fange an, die Query DSL als solche zu verwenden:

curl -XGET 'http://localhost:9200/sneakers/_search?pretty' -d '{ 
    "query" : { 
     "term" : { "brand.title" : "adidas" } 
    } 
} 
' 

Ich bekomme

{ 
    "took" : 9, 
    "timed_out" : false, 
    "_shards" : { 
    "total" : 5, 
    "successful" : 5, 
    "failed" : 0 
    }, 
    "hits" : { 
    "total" : 0, 
    "max_score" : null, 
    "hits" : [ ] 
    } 
} 

Irgendwie gibt Query DSL nichts zurück, selbst die einfachsten Abfragen ausgeführt. Ich betreibe ES 2.3.1.

Irgendeine Idee, warum Query DSL nicht funktioniert? Was mache ich falsch?

Antwort

1

Sie das brand Feld als Typ nested zugeordnet haben, so dass Sie es mit einem nested query abfragen müssen, wie folgt aus:

curl -XGET 'http://localhost:9200/sneakers/_search?pretty' -d '{ 
    "query" : { 
    "nested": { 
     "path": "brand", 
     "query": { 
      "term" : { "brand.title" : "adidas" } 
     } 
    } 
    } 
} 
' 

Hinweis: Ihre Abfrage würde funktionieren, wenn Sie die "type": "nested" von Ihrem Mapping entfernen .

+0

"Typ" entfernt: "verschachtelt" aus Zuordnungen, funktioniert jetzt einwandfrei. Prost. – Inigo

+0

Super, froh, dass es geholfen hat! – Val

Verwandte Themen