16.ES 之 nested 操作案例(2019-05-24)

1.设置mapping信息:
PUT /accounts?error_trace=true
{
  "mappings": {
    "properties": {
      "patient": {
        "type": "nested",
        "properties": {
          "type": {
            "type": "keyword"
          },
          "account_number": {
            "type": "long"
          },
          "balance": {
            "type": "double"
          },
          "firstname": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword"
              }
            }
          },
          "lastname": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword"
              }
            }
          },
          "age": {
            "type": "long"
          },
          "gender": {
            "type": "keyword"
          },
          "address": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword"
              }
            }
          },
          "email": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword"
              }
            }
          },
          "city": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword"
              }
            }
          },
          "country": {
            "type": "keyword"
          }
        }
      }
    }
  }
}

 

2.批量灌数据:
1).脚本(Laravel):
public function handle(\Faker\Generator $faker)
    {
        echo "开始:";
        $numb =0;
        $i    = 0;
        while($numb < 200) {
            $numb++;
            $startTime = microtime(true);
            $wPath     = storage_path("app/account/accounts{$numb}.json");
            $file      = fopen($wPath, "w");
            $i = 10000 * ($numb-1);
            $k = $numb * 10000;
            echo "$i,$k \r\n";
            while ($i < $k) //2000000
            {
                $i++;
                $id = [
                    "index" => [
                        "_id" => $i
                    ]
                ];
                fputs($file, json_encode($id));
                fputs($file, PHP_EOL);
                $rand    = rand(1, 5);
                $total   = [];
                $type    = [0 => 'inpatient', 1 => 'outpatient'];
                $gender  = [0 => 'M', 1 => 'F'];
                $country = [0 => 'France', 1 => 'England', 2 => 'Japan', 3 => 'America', 4 => 'Australia'];
                $one     = [
                    "firstname" => $faker->firstName,
                    "lastname"  => $faker->lastName,
                    "address"   => $faker->address,
                    "email"     => $faker->email,
                    "city"      => $faker->city,
                    "country"   => $country[array_rand($country, 1)]
                ];
                for ($j = 0; $j <= $rand; $j++) {
                    $one["account_number"] = rand(1, 1000000);
                    $one["balance"]        = rand(1, 50);
                    $one["age"]            = rand(10, 88);
                    $one["gender"]         = $gender[array_rand($gender, 1)];
                    $one["type"]           = $type[array_rand($type, 1)];
                    $total['patient'][]    = $one;
                }
                fputs($file, json_encode($total));
                fputs($file, PHP_EOL);
            }
            fclose($file);
        }
        $endTime = microtime(true);
        echo $endTime - $startTime;
    }


2).shell脚本灌数据(本地 linux 内存不够,数据量太大,会报内存溢出异常,所以使用分文件导入):
#!/bin/sh
i=1
while [ $i -le 200 ]
do
        curl -H "Content-Type: application/json" -XPOST "http://192.168.75.206:9200/accounts/patient/_bulk?pretty&refresh" --data-binary @/home/data/account/accounts$i.json
        i=$(( $i+1 ))
done

注:如果是单个文件直接使用:
curl -H "Content-Type: application/json" -XPOST "http://192.168.75.206:9200/accounts/_bulk?pretty&refresh" --data-binary @/home/data/accounts.json

 

3.搜索:
1).搜索全部:
GET /accounts/_search?error_trace=true
{
 "size":10,
  "query": {
    "match_all": {
    }
  }
}

2).bool 搜索:
GET /accounts/_search?error_trace=true
{
  "size": 10,
  "query": {
    "bool": {
      "must": [
        {
          "nested": {
            "path": "patient",
            "query": {
              "bool": {
                "must": [
                  {
                    "match": {
                      "patient.country": "Japan"
                    }
                  }
                ]
              }
            }
          }
        }
      ]
    }
  }
}

3).带聚合的搜索:
GET /accounts/_search?error_trace=true
{
  "size": 10,
  "query": {
    "bool": {
      "must": [
        {
          "nested": {
            "path": "patient",
            "query": {
              "bool": {
                "must": [
                  {
                    "match": {
                      "patient.country": "Japan"
                    }
                  }
                ]
              }
            }
          }
        }
      ]
    }
  },
  "aggs": {
    "patient": {
      "nested": {
        "path": "patient"
      },
      "aggs": {
        "group_by_type": {
          "terms": {
            "field": "patient.type"
          }
        }
      }
    }
  }
}

 

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
首先,这个错误提示是在编译过程中出现的,具体的错误是 C compiler cannot create executables,意思是 C 编译器无法生成可执行文件。那么解决这个问题,一般可以按照以下步骤来进行: 1. 检查编译器是否正确安装 这个问题的根源是编译器无法生成可执行文件,所以我们需要检查编译器是否正确安装。使用以下命令可以查看已经安装的编译器: ``` dpkg --get-selections | grep gcc ``` 如果没有安装或者安装的版本不正确,可以使用以下命令来安装: ``` sudo apt-get install build-essential ``` 2. 检查编译环境是否正确设置 使用以下命令可以检查编译环境是否正确设置: ``` echo $PATH ``` 如果没有包含编译器的路径,可以使用以下命令添加路径: ``` export PATH=$PATH:/usr/local/bin ``` 3. 检查是否有必要的依赖库 有些编译器需要依赖库才能正常工作,如果没有安装这些依赖库,也会出现 C 编译器无法生成可执行文件的问题。使用以下命令可以检查是否安装了 libtool: ``` sudo apt-get install libtool ``` 4. 检查系统架构 最后,还需要检查系统架构是否正确。根据提示信息,可以看到目标系统是 arm-ostl-linux-gnueabi,而本机的系统是 x86_64-pc-linux-gnu,因此需要在编译过程中指定目标系统的架构,比如: ``` ./configure --host=arm-ostl-linux-gnueabi ``` 通过以上步骤,一般就可以解决 C 编译器无法生成可执行文件的问题。如果仍然无法解决,可以查看 config.log 文件,里面会有详细的错误信息,根据错误信息再进行调试。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值