【问题标题】:Elasticsearch: Simple query not matching fieldsElasticsearch:简单查询不匹配字段
【发布时间】:2018-07-10 11:49:20
【问题描述】:

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

我的查询:

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

【问题讨论】:

  • 您能否发布您正在使用的索引和 ES 版本的映射。查询对我来说工作正常。
  • 我在最初的问题中添加了映射和版本

标签: elasticsearch elassandra


【解决方案1】:

试试这个

或者这应该可以工作

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

【讨论】:

  • 没试过。现在有点忙。很高兴听到您的反馈,谢谢。
  • 不 - 没有结果
【解决方案2】:

这个有效:

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

【讨论】:

  • 是的,也更正了我的回答。不知何故错过了添加“产品”键名。
  • 谢谢。但是为什么简单的失败了呢?
  • 因为映射。产品的映射被定义为嵌套映射。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-05-03
  • 1970-01-01
  • 1970-01-01
  • 2020-08-21
  • 1970-01-01
  • 1970-01-01
  • 2017-12-03
相关资源
最近更新 更多