Elasticsearch:简单查询不匹配字段

时间:2018-07-10 11:49:21

标签: elasticsearch elassandra

我想用简单的查询语法查询弹性索引。

我的查询:

{
  "query": {
    "simple_query_string" : {
        "query": "25",
        "fields" : ["product.size"]
    }
  }
}

未返回任何结果,尽管字段中存在一个具有匹配值的条目:

{
  "took" : 869,
  "timed_out" : false,
  "_shards" : {
    "total" : 2,
    "successful" : 2,
    "failed" : 0
  },
  "hits" : {
    "total" : 97241,
    "max_score" : 1.8576174,
    "hits" : [
      {
        "_index" : "deviceinformation",
        "_type" : "deviceinfo",
        "_id" : "314043",
        "_score" : 1.8576174,
        "_source" : {
          "baseinfo" : {
            "material_no" : "314043",
            "dimensional_drawing_nr" : "118600"
          },
          "product" : {
            "size" : "25",
            "range" : "I",
            "type" : "MAC"
          }
      }]
}

我在做什么错了?

编辑: 我正在使用Elassandra 5.5.0.18 = Elasticsearch 5.5.0 + Cassandra 3.11.2 映射摘录:

{
  "deviceinformation" : {
    "mappings" : {
      "deviceinfo" : {
          "product" : {
            "type" : "nested",
            "cql_collection" : "singleton",
            "cql_udt_name" : "product",
            "properties" : {
              "base_size" : {
                "type" : "keyword",
                "cql_collection" : "singleton"
              },
              "pressure_stage" : {
                "type" : "keyword",
                "cql_collection" : "singleton"
              },
              "range" : {
                "type" : "keyword",
                "cql_collection" : "singleton"
              },
              "size" : {
                "type" : "keyword",
                "cql_collection" : "singleton"
              },
              "type" : {
                "type" : "keyword",
                "cql_collection" : "singleton"
              }
            }
          }
}

2 个答案:

答案 0 :(得分:1)

尝试

或者这应该起作用

{
  "query": {
    "nested": {
      "path": "product",
      "query": {
        "match": {
          "proucts.size" : "25"
        }
      }
    }
  }
}

答案 1 :(得分:0)

此作品有效:

{
    "query": {
        "nested": {
            "path": "product",
            "query": {
                "match": {
                    "product.size": "25"
                }
            }
        }
    }
}