1、查询索引字段的映射关系
GET /索引/_mapping
2、查询索引的分词器等设置
GET /索引/_settings
3、根据指定分词器分词
GET /索引/_analyze
{"analyzer" : "standard","text" : "层系"
}
4、term查询
POST /索引/_search
{"query": {"term": {"dbId": "101545"}}
}
5、match查询
POST /tb/_search
{"query": {"match": {"dbId": "19841159f25845008fad2512aa91f48b"}}
}
6、bool查询
6.1 must组合
GET /tb/_search
{"query": {"bool": {"must": [{"terms": {"dbId": [287994]}},{"match": {"original": "层"}}]}}
}
must类似于mysql里面的and命令,上述命令相当于MySQL里面的 where dbId in(287994) and original like '%层%'。注意此处把match命令当成了mysql的like命令,其实这两个命令还是有明显区别的。
6.2must与should组合
POST /tb/_search
{"query": {"bool": {"must": [{"term": {"dbId": {"value": "19841159f25845008fad2512aa91f48b"}}}],"should": [{"match": {"original": "边水"}}],"minimum_should_match": 1}}
}
上述命令类似于MySQL命令:where dbId = '19841159f25845008fad2512aa91f48b' and original like '%边水%'。如果上述命令不加上minimum_should_match: 1,则类似于MySQL命令:where dbId = '19841159f25845008fad2512aa91f48b'。
7、自定义脚本过滤
GET /tb/_search
{"query": {"bool": {"must": [{"terms": {"dbId": ["19841159f25845008fad2512aa91f48b"]}},{"match_phrase": {"original.standard": {"query": "层系"}}}],"filter": [{"script": {"script": {"lang": "painless","source": "String str = params.val;String strLower = params.valLower;String val = doc['original.keyword'].value;return str.contains(val) || strLower.contains(val.toLowerCase());","params": {"val": "侏罗层系主力区块年注采比变化","valLower": "侏罗层系主力区块年注采比变化"}}}}]}}
}