Elasticsearch依据字段长度过滤

查询title字段的长度小于9的文档

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
GET /nm*/_search
{
"query": {
"filtered": {
"query": {
"match": {
"title": {
"query": "黄晓明和杨颖结婚",
"operator": "and",
"minimum_should_match": "90%"
}
}
},
"filter": {
"script" : {
"script" : "doc['title'].size() < 9"
}
}
}
}
}

代理模式

代理模式

为另一个对象提供一个替身或占位符以访问这个对象.

代理模式中远程代理和动态代理比较常用

Elasticsearch配置ik分词器

假定你已经安装了elasticsearch2.1.0和maven, 下面的步骤针对elasticsearch2.1.0有效, 其它版本可能不使用

下载ik

因为我的elasticsearch是2.1.0,所以去这里下载https://github.com/medcl/elasticsearch-analysis-ik/releases/tag/v1.6.1

其它版本的elasticsearch对应的ik去https://github.com/medcl/elasticsearch-analysis-ik 下载

解压ik,并进入ik

执行 mvn package 编译ik

复制文件

将elasticsearch-analysis-ik-master/target/releases/elasticsearch-analysis-ik-1.6.1.zip 拷贝到es的plugin/ik目录下并解压

同时将elasticsearch-analysis-ik-master/config/ik文件夹拷贝到es的config下

然后重启es,就可以了.

Java发送邮件

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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package com.google.utils;

import java.util.Properties;

import javax.mail.Authenticator;
import javax.mail.Message.RecipientType;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

/**
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.7</version>
</dependency>
*/
public class EmailUtil {

private static Properties properties = null;

public static void init(Properties properties)
{
EmailUtil.properties = properties;
}

public static void send(String subject, String message) {
try {
Authenticator authenticator = new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
String userName = properties.getProperty("mail.user");
String password = properties.getProperty("mail.password");
return new PasswordAuthentication(userName, password);
}
};
Session session = Session.getInstance(properties, authenticator);
MimeMessage mime = new MimeMessage(session);
InternetAddress form = new InternetAddress(properties.getProperty("mail.user"));
mime.setFrom(form);
InternetAddress to = new InternetAddress(properties.getProperty("main.to"));
mime.setRecipient(RecipientType.TO, to);

mime.setSubject(subject);
mime.setContent(message, "text/html;charset=UTF-8");

Transport.send(mime);
} catch (AddressException e) {
e.printStackTrace();
} catch (MessagingException e) {
e.printStackTrace();
}
}

public static void main(String[] args) {
Properties properties = new Properties();
properties.put("mail.smtp.auth", "true");
properties.put("mail.smtp.host", "smtp.exmail.qq.com");
properties.put("mail.user", "user1@example.com");
properties.put("mail.password", "password");
properties.put("main.to","user2@qq.com");

EmailUtil.init(properties);
EmailUtil.send("hello", "这是来自大洋彼岸的声音!");
}

}

将启动命令中包含某个字符串的进行杀死

1
2
3
4
[root@dn01 testbash]# ps -ef | grep hello
root 24794 7457 0 11:09 pts/2 00:00:00 sh hello.sh
root 24910 7457 0 11:09 pts/2 00:00:00 sh hello.sh
root 25295 7457 0 11:11 pts/2 00:00:00 grep hello

使用

1
ps aux | grep hello | grep -v grep |awk '{print $2}'| xargs kill -9

可以将上述的前两个进程杀死