Runnable

strong to refuse


  • 首页

  • 标签

  • 归档

elasticsearch-terms-execution

发表于 2019-12-03
1
2
3
{
"terms" : { "field_name" : ["value1", "value2"], "execution" : "bool" }
}

“reason”: “[terms] query does not support [execution]”,
这种方式已经不支持了,目前只有用must没有找到更优雅的写法。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
POST /goods_index/_search
{
"explain": true,
"query": {
"bool": {
"filter": [
{
"bool": {
"must": [
{
"term": {
"categoryIds": {
"value": 1
}
}
},
{
"term": {
"categoryIds": {
"value": 2
}
}
}
]
}
}
]
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
POST /my_index/_search?pretty
{
"query": {
"terms": {
"color" : {
"index" : "my_index",
"id" : "3",
"path" : "color"
}
}
}
}

POST /my_index/_search?pretty
{
"query": {
"terms_set": {
"color": {
"terms": [
"green",
"blue"
],
"minimum_should_match_script": {
"source": "Math.min(params.num_terms, 4)"
},
"boost": 1
}
}
}
}

ps.

  • https://www.elastic.co/guide/en/elasticsearch/reference/7.0/query-dsl-terms-set-query.html#terms-set-query-script
  • https://www.elastic.co/guide/cn/elasticsearch/guide/current/_finding_multiple_exact_values.html
  • https://discuss.elastic.co/t/is-there-an-alternative-solution-to-terms-execution-and-on-es-2-x/41089
  • https://github.com/elastic/elasticsearch/issues/1568

hexo错误

发表于 2019-11-19

Template render error: (unknown path) [Line 8, Column 25]

参考

  • hexo
  • https://github.com/iissnan/theme-next-docs/issues/79

插件 hexo-generate-feed 还有 hexo-generate-sitemap 和 hexo3 不兼容!

Hello World

发表于 2019-11-19

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

Quick Start

Create a new post

1
$ hexo new "My New Post"

More info: Writing

阅读全文 »

kibana.nginx

发表于 2019-08-29

nginx配置文件 kibana.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
server {
listen 80;

server_name <YourKibanaIP>;

auth_basic "Restricted Access";
auth_basic_user_file /etc/nginx/htpasswd.users.kibana;

location / {
proxy_pass http://localhost:5601;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}

生成http认证用户

1
echo "kadmin:`openssl passwd -apr1`" | sudo tee -a ./htpasswd.users.kibana

elasticsearch计算词频

发表于 2019-07-23

安装环境:
elasticsearch-7.0
analysis_ik

1
2
3
4
5
6
7
8
9
10
11
12
13
14
GET /sale_comment/_search
{
"size": 0,
"aggs":{
"content":{
"terms":{
"size":1000,
"field":"content",
"include":"[\u4E00-\u9FA5]{2,6}",
"exclude":"的.*|很.*|不.*|了.*|也.*|買.*|好.*|錯.*"
}
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"aggregations": {
"content": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 205350,
"buckets": [
{
"key": "舒服",
"doc_count": 6051
},
{
"key": "非常",
"doc_count": 5583
},
{
"key": "效果",
"doc_count": 5289
},
{
"key": "真的",
"doc_count": 3404
},
{
"key": "到了",
"doc_count": 3383
}
]
}
}

linux.tools

发表于 2019-07-23

apt install zsh git vagrant wget curl vim npm nvm tldr jmeter nmap

sudo npm install -g commitizen

phpbrew

sh -c “$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.s
h)”

sudo add-apt-repository ppa:wiznote-team
sudo apt-get update
sudo apt-get install wiznote

sudo apt-get install openssl

sudo apt-get install libssl-dev

nvm

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.0/install.sh | bash
npm install -g n

supervisor pm2

xhprof.php7

发表于 2019-05-22

git clone https://github.com/tideways/php-xhprof-extension.git

1
2
3
4
5
phpize 
yum install autoconf
./configure
make
make install

git clone https://github.com/preinheimer/xhprof.git

nginx配置
fastcgi_param PHP_VALUE “auto_prepend_file=/home/xhprof/external/header.php”;

mysql的innodb幻读问题

发表于 2019-03-20

MySQL InnoDB事务的隔离级别有四级,默认是“可重复读”(REPEATABLE READ)。

未提交读(READ UNCOMMITTED)。另一个事务修改了数据,但尚未提交,而本事务中的SELECT会读到这些未被提交的数据(脏读)。
提交读(READ COMMITTED)。本事务读取到的是最新的数据(其他事务提交后的)。问题是,在同一个事务里,前后两次相同的SELECT会读到不同的结果(不重复读)。
可重复读(REPEATABLE READ)。在同一个事务里,SELECT的结果是事务开始时时间点的状态,因此,同样的SELECT操作读到的结果会是一致的。但是,会有幻读现象(稍后解释)。
串行化(SERIALIZABLE)。读操作会隐式获取共享锁,可以保证不同事务间的互斥。
四个级别逐渐增强,每个级别解决一个问题。

脏读,最容易理解。另一个事务修改了数据,但尚未提交,而本事务中的SELECT会读到这些未被提交的数据。
不重复读。解决了脏读后,会遇到,同一个事务执行过程中,另外一个事务提交了新数据,因此本事务先后两次读到的数据结果会不一致。
幻读。解决了不重复读,保证了同一个事务里,查询的结果都是事务开始时的状态(一致性)。但是,如果另一个事务同时提交了新数据,本事务再更新时,就会“惊奇的”发现了这些新数据,貌似之前读到的数据是“鬼影”一样的幻觉。
借鉴并改造了一个搞笑的比喻:

脏读。假如,中午去食堂打饭吃,看到一个座位被同学小Q占上了,就认为这个座位被占去了,就转身去找其他的座位。不料,这个同学小Q起身走了。事实:该同学小Q只是临时坐了一小下,并未“提交”。
不重复读。假如,中午去食堂打饭吃,看到一个座位是空的,便屁颠屁颠的去打饭,回来后却发现这个座位却被同学小Q占去了。

幻读。假如,中午去食堂打饭吃,看到一个座位是空的,便屁颠屁颠的去打饭,回来后,发现这些座位都还是空的(重复读),窃喜。走到跟前刚准备坐下时,却惊现一个恐龙妹,严重影响食欲。仿佛之前看到的空座位是“幻影”一样。

一些文章写到InnoDB的可重复读避免了“幻读”(phantom read),这个说法并不准确。

  • 获得当前会话的TRX_ID 事务ID

    start transaction;
    SELECT TRX_ID FROM INFORMATION_SCHEMA.INNODB_TRX WHERE TRX_MYSQL_THREAD_ID = CONNECTION_ID();
    commit;

  • 查询 正在执行的事务:

    SELECT * FROM information_schema.INNODB_TRX

  • 查看正在锁的事务

    SELECT * FROM INFORMATION_SCHEMA.INNODB_LOCKS;

  • 查看等待锁的事务

SELECT * FROM INFORMATION_SCHEMA.INNODB_LOCK_WAITS;

如果使用普通的读,会得到一致性的结果,如果使用了加锁的读,就会读到“最新的”“提交”读的结果。

本身,可重复读和提交读是矛盾的。在同一个事务里,如果保证了可重复读,就会看不到其他事务的提交,违背了提交读;如果保证了提交读,就会导致前后两次读到的结果不一致,违背了可重复读。

可以这么讲,InnoDB提供了这样的机制,在默认的可重复读的隔离级别里,可以使用加锁读去查询最新的数据。

http://dev.mysql.com/doc/refman/5.0/en/innodb-consistent-read.html

If you want to see the “freshest” state of the database, you should use either the READ COMMITTED isolation level or a locking read:
SELECT * FROM t_bitfly LOCK IN SHARE MODE;


结论:MySQL InnoDB的可重复读并不保证避免幻读,需要应用使用加锁读来保证。而这个加锁度使用到的机制就是next-key locks。

概率计算

发表于 2019-01-11
  • 算法一
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/**
* 全概率计算
*
* @param array $p array('a'=>0.5,'b'=>0.2,'c'=>0.4)
* @return string 返回上面数组的key
*/
function random($ps){
static $arr = array();
$key = md5(serialize($ps));

if (!isset($arr[$key])) {
$max = array_sum($ps);
foreach ($ps as $k=>$v) {
$v = $v / $max * 10000;
for ($i=0; $i<$v; $i++) $arr[$key][] = $k;
}
}
return $arr[$key][mt_rand(0,count($arr[$key])-1)];
}
  • 算法二
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

/**
* 根据权重概率获取
* @param $weights [ { k => weight } ]
* @return int|string
*/
public function getRand( $weights )
{
$result = '';

$weightSum = array_sum( $weights );

foreach( $weights as $key => $weight )
{
$randNum = mt_rand( 1, $weightSum );
if( $randNum <= $weight )
{
$result = $key;
break;
}
$weightSum -= $weight;
}

return $result;
}

sprintBoot-headFirst

发表于 2018-12-18

https://start.spring.io/

mvn clean install

mvn spring-boot:run

1234…7

laugh

lanmp, ELK, go, python, vue, 分布式, k8s, docker, CI/CD

62 日志
5 分类
26 标签
© 2020 laugh
由 Hexo 强力驱动
|
主题 — NexT.Mist v5.1.4