0

我是 elasticsearch 新手,我使用的是 5.1.2 版。我有这个索引,我不知道我是否使用 _source 字段创建得很好。我想要一个返回所有带有 loc = XXY 和 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
              }
            }
          }
        }
      }
    }
  }
}
4

1 回答 1

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

于 2017-01-31T10:26:45.060 回答