簡體   English   中英

如果ES中沒有定義Field的映射,我們可以查詢嗎?

[英]Can we query on Field if its mapping is not defined in ES?

是否可以查詢未映射到訂單的字段? 使用彈性搜索 7.4

我創建了一個只有 1 個映射的索引

索引名稱 - test_date_mapping_with_null 動態映射 - 錯誤屬性 - 城市 -> 文本。

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

插入帶有 published_at 字段的文檔

POST test_date_mapping_with_null/_doc/1
{
  "city": "NY",
  "published_at": "2022-01-01T06:58:27.000Z"
}
POST test_date_mapping_with_null/_doc/2
{
  "city": "Paris",
  "published_at": "2022-01-02T06:58:27.000Z"
}
POST test_date_mapping_with_null/_doc/3
    {
      "city": "Mumbai",
      "published_at": "2022-01-03T06:58:27.000Z"
    }
POST test_date_mapping_with_null/_doc/4
    {
      "city": "Tokyo",
      "published_at": "2022-01-04T06:58:27.000Z"
    }

映射看起來像這樣

"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(即城市 -> 紐約、巴黎和孟買文檔)

您的索引映射,目前只包括city字段的映射,它沒有published_at字段的映射,因為您在索引映射中設置了"dynamic": "false"

這意味着published_at存儲在Elasticsearch中,但是這個字段在Elasticsearch中沒有索引。簡單來說,這意味着你不能對published_at字段進行任何搜索

不,如果字段未在 Elasticsearch 中編入索引(如您定義的動態:false,它不會被索引),您將無法查詢這些字段,但是當您使用_search或獲取文檔時,您可以將它們視為_source的一部分按文檔 ID。

如果要查詢該字段,請將映射從dynamic:false更改為dynamic:true或在映射中顯式添加字段(如果您想要 dynamic:false)。

您不能查詢映射中未指定的字段,並且 dynamic 設置為 false。 您只能將這些字段存儲在 _source 中。 https://www.elastic.co/guide/en/elasticsearch/reference/7.4/dynamic.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM