2017-01-31 1 views
0

Ich bin neu mit elasticsearch, ich benutze Version 5.1.2. Ich habe diesen Index, ich weiß nicht, ob ich gut mit dem Feld _source erstellt habe. Ich möchte eine Abfrage, die alle Register mit loc = XXY und part = Z zurückgibt, wie kann ich es tun? Ich versuche damit aber nicht funktioniert. Irgendeine Idee?Elasticsearch Abfrage Begriffssuche, wie es mit _source tun?

{ 
    "took": 2, 
    "timed_out": false, 
    "_shards": { 
    "total": 5, 
    "successful": 5, 
    "failed": 0 
    }, 
    "hits": { 
    "total": 107271, 
    "max_score": 1, 
    "hits": [ 
     { 
     "_index": "my_index", 
     "_type": "po", 
     "_id": "0", 
     "_score": 1, 
     "_source": { 
      "loc": "XXX", 
      "part": "YY", 
      "order_qty": "16", 
     } 
     }, 
     { 
     "_index": "my_index", 
     "_type": "po", 
     "_id": "14", 
     "_score": 1, 
     "_source": { 
      "loc": "XXY", 
      "part": "Z", 
      "order_qty": "7", 
     } 
     }, 
     { 
     "_index": "my_index", 
     "_type": "po", 
     "_id": "19", 
     "_score": 1, 
     "_source": { 
      "loc": "XXY", 
      "part": "Z", 
      "order_qty": "8", 
     } 
     ... 

Die Abfrage, die ich verwende, aber nicht funktioniert:

GET my_index/po/_search 
{ 
    "query" : { 
     "term" : { "loc" : "XXY", "part": "Z"} 
    } 
} 

Mappings:

{ 
    "my_index": { 
    "mappings": { 
     "po": { 
     "properties": { 
      "loc": { 
      "type": "text", 
      "fields": { 
       "keyword": { 
       "type": "keyword", 
       "ignore_above": 256 
       } 
      } 
      }, 
      "order_qty": { 
      "type": "text", 
      "fields": { 
       "keyword": { 
       "type": "keyword", 
       "ignore_above": 256 
       } 
      } 
      }, 
      "part": { 
      "type": "text", 
      "fields": { 
       "keyword": { 
       "type": "keyword", 
       "ignore_above": 256 
       } 
      } 
      } 
     } 
     } 
    } 
    } 
} 

Antwort

1

Sie sollten etwas tun:

POST my_index/po/_search 
{ 
    "query": { 
    "bool": { 
     "must": [ 
     { "match": { "loc": "XXY" }}, 
     { "match": { "part": "Z" }} 
     ] 
    } 
    } 
} 

Einige zusätzliche Informationen Über Übereinstimmungsabfrage - https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html

+0

Es tut mir leid, aber nicht funktioniert ... –

+0

Was bedeutet es, es funktioniert nicht? möglicherweise haben Sie falsche Daten oder falsche Zuordnungen, PLZ zeigen sie – Mysterion

+0

falsche Zuordnungen? Was muss ich zuordnen? –

Verwandte Themen