Elasticsearch 參考指南(映射參數properties)

映射參數properties

類型映射、object字段和nested字段包含子字段,稱爲properties,這些屬性能夠是任何數據類型,包括objectnested,能夠添加屬性:app

  • 在建立索引時顯式地定義它們。
  • 在使用PUT mapping API添加或更新映射類型時顯式地定義它們。
  • 僅經過索引包含新字段的文檔就能夠動態地映射屬性。

下面是一個向映射類型、object字段和nested字段添加properties的示例:code

PUT my_index
{
  "mappings": {
    "properties": { 
      "manager": {
        "properties": { 
          "age":  { "type": "integer" },
          "name": { "type": "text"  }
        }
      },
      "employees": {
        "type": "nested",
        "properties": { 
          "age":  { "type": "integer" },
          "name": { "type": "text"  }
        }
      }
    }
  }
}

PUT my_index/_doc/1 
{
  "region": "US",
  "manager": {
    "name": "Alice White",
    "age": 30
  },
  "employees": [
    {
      "name": "John Smith",
      "age": 34
    },
    {
      "name": "Peter Brown",
      "age": 26
    }
  ]
}
  • 頂級映射定義中的屬性。
  • manager對象字段下的屬性。
  • employees嵌套字段下的屬性。
  • 對應於上述映射的示例文檔。
properties設置容許在同一索引中爲同名字段設置不一樣的設置,可使用 PUT mapping API將新屬性添加到現有字段。

點符號

內部字段能夠在查詢、聚合等中引用,使用點符號:對象

GET my_index/_search
{
  "query": {
    "match": {
      "manager.name": "Alice White"
    }
  },
  "aggs": {
    "Employees": {
      "nested": {
        "path": "employees"
      },
      "aggs": {
        "Employee Ages": {
          "histogram": {
            "field": "employees.age",
            "interval": 5
          }
        }
      }
    }
  }
}
必須指定到內部字段的完整路徑。
相關文章
相關標籤/搜索