字段_source和有什么区别?弹性搜索

时间:2019-09-19 03:05:49

标签: elasticsearch

嗨,我得到json数据,然后有一个问题。

fields_source有什么区别?

为什么Date同时属于sourcefields而不是其余部分?

映射时您做错了什么吗?溢出是我的第一次,但是“请添加更多细节”对我来说很难。

{
  "_index": "nameindex",
  "_type": "_doc",
  "_id": "7WRlR20BIPcwc_JrL41I",
  "_score": 1,
  "_source": {
    "Date": "2019-09-18 11:50:52",
    "@timestamp": "2019-09-19T02:41:14.317Z",
    "input": {},
    "tags": [
      "_dateparsefailure"
    ],
    "ID": "ddd",
    "host": {
      "hostname": "KC20114"
    },
  },
  "fields": {
    "@timestamp": [
      "2019-09-19T02:41:14.317Z"
    ],
    "Date": [
      "2019-09-18T11:50:52.000Z"
    ]
  }
}

这是我的索引映射

{
  "nameindex" : {
    "aliases" : { },
    "mappings" : {
      "properties" : {
        "@timestamp" : {
          "type" : "date"
        },
        "host" : {
          "properties" : {
            "hostname" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            }
          }
        },
        "input" : {
          "type" : "object"
        },
        "ID" : {
          "type" : "keyword"
        },
        "Date" : {
          "type" : "date",
          "format" : "yyyy-MM-dd HH:mm:ss"
        }
      }
    },
    "settings" : {
      "index" : {
        "creation_date" : "1568860876496",
        "number_of_shards" : "1",
        "number_of_replicas" : "1",
        "uuid" : "D__VED83T7i38Qs3RqlrCQ",
        "version" : {
          "created" : "7030099"
        },
        "provided_name" : "nameindex"
      }
    }
  }
}

它是查询

PUT /_template/nameindex
{
    "index_patterns": ["nameindex*"],
    "mappings": {
    "properties": {
      "@timestamp": {
        "type": "date"
      },
      "host": {
        "properties": {
          "hostname": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          }
        }
      },
      "input": {
        "type": "object"
      },
      "Date": {
        "type": "date",
        "format": "yyyy-MM-dd HH:mm:ss"
      },
      "ID": {
        "type": "keyword"
      }
    }
  }  
}

它是json日志。 我制作了此日志,然后filebeat自动获取了

{ "userID" : "ddd", "Date" : "2019-09-18 11:50:52" }

1 个答案:

答案 0 :(得分:0)

您在_source中看到的是已编制索引的实际文档,即Beats发送到您的Elasticsearch服务器的内容。因此,它包含Beats捕获的所有内容以及Beats添加的一些其他字段。

您在fields中看到的就是我们所说的doc_values,即在文档索引时建立的磁盘数据结构,这使在这些字段上的排序和聚合更加容易和高效。

默认情况下,在Kibana中,对于日期类型的所有字段,“发现”视图将始终在查询中同时包含_sourcedocvalue_fields。通过单击“检查”,然后单击“请求”,可以看到Kibana发送的查询。