二、問(wèn)題
在做一個(gè)需求的時(shí)候,需要按照電話號(hào)碼查詢用戶關(guān)系,所以我這邊先講相關(guān)信息同步到es,但是電話號(hào)碼是加密的,所以顯示的字符串是雜亂的,既有字母,又有斜杠等號(hào)等字符,在進(jìn)行分詞查詢的時(shí)候匹配不到相應(yīng)的數(shù)據(jù),所以需要對(duì)電話號(hào)碼字段指定為不分詞的查詢即完全匹配
三、解決
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldIndex;
@Document(indexName = "address_index",type = "t_address")
public class Address{
@Id
private Long id ;
private String address;
private String province;
private String city;
//@Field(type = FieldType.String , index = FieldIndex.not_analyzed)
@Field(index = FieldIndex.not_analyzed)
private String mobile;
public static long getSerialVersionUID() {
return serialVersionUID;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getProvince() {
return province;
}
public void setProvince(String province) {
this.province = province;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
在代碼中指定某個(gè)字段不進(jìn)行分詞搜索時(shí)候,需要對(duì)其類型進(jìn)行指定,否則查看索引如下圖

not_analyzed.png
如果指定了字段類型,并且該字段不進(jìn)行分詞搜索,則可以看到其index為not_analyzed

analyzed.png
四、es后臺(tái)管理使用遇到的問(wèn)題
{
"query": {
"bool": {
"filter": {
"terms": {
"userNo": ["5832794"]
}
}
}
}
}

image.png
記住這里的查詢,方法提交方式是POST、POST、POST