2017-01-31 24 views
0

私はelasticsearchで新しいです、私はバージョン5.1.2を使用しています。 私はこのインデックスを持っていますが、わかりません。私が_sourceフィールドでうまく作成したかどうか。 loc = XXYとpart = Zのすべてのレジスタを返すクエリが必要です。どうすればいいですか?私はこれで試していますが、うまくいきません。何か案が?弾性検索クエリの検索、_sourceで検索する方法

{ 
    "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", 
     } 
     ... 

私が使用していたクエリではなく、作品:

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

マッピング:

{ 
    "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 
       } 
      } 
      } 
     } 
     } 
    } 
    } 
} 

答えて

1

あなたはこのような何か行う必要があります。

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

いくつかの追加情報を一致クエリについて - https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html

+0

申し訳ありませんが、動作していません... –

+0

それはどういう意味ですか?あなたが間違ったデータや間違ったマッピングを持っている可能性があります、それらを示すplz – Mysterion

+0

間違ったマッピング?私はマップする必要がありますか? –