elasticsearch 如果ES中未定义字段的Map,是否可以查询字段?

piah890a  于 2022-12-11  发布在  ElasticSearch
关注(0)|答案(3)|浏览(303)

是否可以查询未与订单Map的字段??使用ElasticSearch7.4
我已经创建了一个只有1个Map的索引
索引名称- test_date_mapping_with_null动态Map-假属性-城市-〉文本。

{
  "settings" : {
    "number_of_shards" : 2,
    "number_of_replicas" : 1
  },
  "mappings" : {
    "dynamic":false,
    "properties" : {
        "city" : { "type" : "text" }
    }
  }
}

插入包含published_at字段的文档
第一个
Map如下

"mappings": {
      "_doc": {
        "dynamic": "false",
        "properties": {
          "city": {
            "type": "text"
          }
        }
      }
    }

立即搜索查询

GET test_date_mapping_with_null/_search
{
  "query": {
    "range": {
      "published_at": {
        "gte": "2022-01-01T00:58:27.000Z",
        "lte": "2022-01-03T23:58:27.000Z",
        "boost": 2.0
      }
    }
  }
}

实际- ES返回所有单据。预期- ES应仅返回单据1、2和3(即城市-〉纽约、巴黎和孟买单据)

yzxexxkh

yzxexxkh1#

您的索引Map当前仅包括city字段的Map,它没有published_at字段的Map,因为您已在索引Map中设置了"dynamic": "false"
这意味着published_at存储在Elasticsearch中,但该字段在Elasticsearch中没有索引。

dxxyhpgq

dxxyhpgq2#

不,如果在Elasticsearch中没有索引,您就不能查询这些字段(因为您定义了dynamic:false,它不会是索引),但是当您使用_search或通过文档ID获取文档时,您可以将它们作为_source的一部分来查看。
如果要查询字段,请将Map从dynamic:false更改为dynamic:true,或者在Map中显式添加字段(如果要使用dynamic:false)。

dgenwo3n

dgenwo3n3#

不能查询Map中未指定且dynamic设置为false字段只能将这些字段存储在_source. https://www.elastic.co/guide/en/elasticsearch/reference/7.4/dynamic.html

相关问题