一、查看索引字段类型
GET order_doc/_mapping
二、ik_max_word
GET _analyze
{
"analyzer": "ik_max_word",
"text": "小米"
}
三、ik_smart
GET _analyze
{
"analyzer": "ik_smart",
"text": "好的吧"
}
四、SQL
GET /_sql?format=txt
{
"query":"select school,schoolFullName from qmschool"
}
五、查询所有
GET /qmschool/_search
{
"query": {
"match_all": {}
}
}
六、查询带条件
GET /qmschool/_search
{
"query": {
"match": {
"schoolFullName": {
"query": "中山大学",
"operator": "AND",
"prefix_length": 0,
"max_expansions": 50,
"fuzzy_transpositions": true,
"lenient": false,
"zero_terms_query": "NONE",
"auto_generate_synonyms_phrase_query": true,
"boost": 1.0
}
}
}
}
七、查询条件嵌套
select * from where cityCode = '430100000000' and (cityName = '还读书文化' or title='还读书文化')
GET /qm_goods/_search
{
"from": 0,
"size": 10,
"query": {
"bool": {
"must": [
{
"term": {
"cityCode": {
"value": "430100000000",
"boost": 1.0
}
}
},
{
"bool": {
"should": [
{
"multi_match": {
"query": "还读书文化",
"fields": [
"cityName^1.0",
"topicStr^1.0"
],
"type": "best_fields",
"operator": "AND",
"slop": 0,
"prefix_length": 0,
"max_expansions": 50,
"zero_terms_query": "NONE",
"auto_generate_synonyms_phrase_query": true,
"fuzzy_transpositions": true,
"boost": 1.0
}
},
{
"multi_match": {
"query": "还读书文化",
"fields": [
"address^1.0",
"buTypeStr^1.0",
"content^1.0",
"title^1.0"
],
"type": "best_fields",
"operator": "OR",
"slop": 0,
"prefix_length": 0,
"max_expansions": 50,
"zero_terms_query": "NONE",
"auto_generate_synonyms_phrase_query": true,
"fuzzy_transpositions": true,
"boost": 1.0
}
}
]
}
}
],
"adjust_pure_negative": true,
"boost": 1.0
}
}
}
java代码
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
if (StringUtils.isNotBlank(fieldterm)) {
if (StringUtils.isBlank(termValue)) {
throw new QiMiaoException("termValue值不能为空");
}
TermQueryBuilder termQueryBuilder = QueryBuilders.termQuery(fieldterm, termValue);
boolQueryBuilder.must(termQueryBuilder);
}
if (StringUtils.isNotBlank(keyword)) {
BoolQueryBuilder boolShouldQueryBuilder = QueryBuilders.boolQuery();
//精确查询(关键字不分词查询)
if (CollectionUtil.isNotEmpty(fieldUnSplitList)) {
MultiMatchQueryBuilder unSplitMultiMatchQueryBuilder = QueryBuilders.multiMatchQuery(keyword, ArrayUtil.toArray(fieldUnSplitList, String.class));
unSplitMultiMatchQueryBuilder.operator(Operator.AND);
boolShouldQueryBuilder.should(unSplitMultiMatchQueryBuilder);
}
//分词查询
if (CollectionUtil.isNotEmpty(fieldList)) {
MultiMatchQueryBuilder multiMatchQueryBuilder = QueryBuilders.multiMatchQuery(keyword, ArrayUtil.toArray(fieldList, String.class));
multiMatchQueryBuilder.operator(Operator.OR);
boolShouldQueryBuilder.should(multiMatchQueryBuilder);
}
boolQueryBuilder.must(boolShouldQueryBuilder);
}
builder.query(boolQueryBuilder);
网友评论