Elasticsearch query term search,如何用_source来做?

Elasticsearch query term search, how to do it with _source?

我是 elasticsearch 的新手,我使用的是 5.1.2 版。 我有这个索引,我不知道我是否用 _source 字段创建得很好。 我想要一个查询 returns all registers with loc = XXY and part = Z,我该怎么做?我正在尝试这个但没有用。有什么想法吗?

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

你应该这样做:

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