keyword不分词
例如: washing machin
term: washing - 无结果
washing machine - 有结果
text分词
例如:{
"name":"washing machine",
"tag":"electric household"
}
term: household - 有结果
electric household - 无结果【说明text类型的字段会被分词,查询的时候如果用拆开查可以查询的到,但是要是直接全部查,就是查询不到】
=========================================================================
term 查询keyword字段【term不会分词,keyword也不分词。需要完全匹配才可】
term 查询text字段【text字段分词,而term不分词,所以term查询的条件必须是text字段分词后的某一个】
=========================================================================
match 查询keyword字段【match分词,keyword不分词。需要完全匹配才可】
match 查询text字段【match分词,text字段分词,只要match的分词将结果和text分词结果有相同的就匹配】
=================================================================================
match_phrase 查询keyword字段【需要完全匹配才可】
match_phrase 查询text字段【match_phrase是分词的,text也是分词的。match_phrase的分词结果必须在text字段分词中都包含,而且顺序必须相同,而且必须都是连续的】
=========================================================================
match_phrase_prefix 和 match_phrase 用法是一样的,区别就在于它允许对最后一个词条前缀匹配
=========================================================================
query_string查询keyword字段【即使全匹配也无结果】
query_string查询text字段【和match_phrase区别的是,不需要连续,顺序还可以调换】
=========================================================================
multi_match:
{
"query": {
"multi_match": {
"type": "most_fields",
"query": "待查询句子",
"fields": [
"字段1",
"字段2",
"字段3"
]
}
}
}
=========================================================================
多个match查询:
{
"query": {
"bool": {
"should": [
{
"match": {
"字段1": "待查询句子"
}
},
{
"match": {
"字段3": "待查询句子"
}
},
{
"match": {
"字段3": "待查询句子"
}
}
]
}
}
}
=========================================================================
wildcard通配符查询
【允许使用通配符* 和 ?来进行查询
*代表0个或多个字符
?代表任意一个字符】
ES删除
curl -POST '10.128.55.1:9200/st_twitter_ref/st_twitter_ref/_delete_by_query?pretty' -d '
{
"query": {
"range": {
"pubtime": {
"gte": "2022-07-29 00:00:00"
}
}
}
}'
curl -XGET 'http://xx:9200/youtube_info/youtube_info/_search?pretty' -H 'Content-Type:application/json' -d'
{
"size":1
}'
curl -XPOST 'http://xx:9200/news_info/news_info/_delete_by_query?pretty' -H 'Content-Type:application/json' -d'
{
"query": {
"term": {
"site":"XXXXYYYY"
}
}
}'
curl -POST 'http://xx:9200/youtube_info/youtube_info/_delete_by_query?pretty' -d '
{
"query": {
"match_all": {
}
}
}'
根据id查询
"query": {
"ids": {
"values": [1,2,3]
}
}
curl -XDELETE 'http://xx:9200/youtube_info/youtube_info'
curl -XGET 'http://xx:9200/youtube_info/_mappings?pretty'
curl -XGET 'http://xx:9200/youtube_info/_mappings?pretty'