• es的批量导入


      因为使用的是容器,所以,这里不使用文件的方式。目前,有一个疑问,发现bulk进入的数据,字段类型是没有问题的,之前没有设置mapping的情况下。

    1.批量导入

      Bulk:ES提供了⼀个叫 bulk 的API 来进⾏批量操作

    2.示例

    POST /_bulk
    {"index": {"_index": "book","_type": "_doc","_id": 1}}
    {"name": "权⼒的游戏"}
    {"index": {"_index": "book","_type": "_doc","_id": 2}}
    {"name": "疯狂的⽯头"}
    

      效果:

    {
      "took" : 0,
      "timed_out" : false,
      "_shards" : {
        "total" : 1,
        "successful" : 1,
        "skipped" : 0,
        "failed" : 0
      },
      "hits" : {
        "total" : {
          "value" : 2,
          "relation" : "eq"
        },
        "max_score" : 1.0,
        "hits" : [
          {
            "_index" : "book",
            "_type" : "_doc",
            "_id" : "1",
            "_score" : 1.0,
            "_source" : {
              "name" : "权⼒的游戏"
            }
          },
          {
            "_index" : "book",
            "_type" : "_doc",
            "_id" : "2",
            "_score" : 1.0,
            "_source" : {
              "name" : "疯狂的⽯头"
            }
          }
        ]
      }
    }
    

      

    3.截图

      

    二:测试上面的疑问

    1.测试

    PUT /test/_doc/1
    {
      "name":"tom",
      "age":10
    }
    
    GET /test/_mapping
    

      结果:

    {
      "test" : {
        "mappings" : {
          "properties" : {
            "age" : {
              "type" : "long"
            },
            "name" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            }
          }
        }
      }
    }
    

      

    2.解释

      这是es中的 multi-fields.:https://www.elastic.co/guide/en/elasticsearch/reference/current/multi-fields.html

      

    3.官网的说明

      It is often useful to index the same field in different ways for different purposes.

      This is the purpose of multi-fields.

      For instance, a string field could be mapped as a text field for full-text search, and as a keyword field for sorting or aggregations

  • 相关阅读:
    网络编程
    初识正则表达式
    面向对象---内置函数,反射,内置方法
    面向对象----属性,类方法,静态方法
    面向对象--抽象类,多态,封装
    面向对象--继承
    初识面向对象
    类名称空间,查询顺序,组合
    经典例题
    ⽣成器和⽣成器表达式
  • 原文地址:https://www.cnblogs.com/juncaoit/p/12664015.html
Copyright © 2020-2023  润新知