elasticsearch three basic query (the English word) match the query

#match查询
#match query知道分词器的存在,会对filed进行分词操作, 然后再查询
GET /ib3/user/_search 
{ 
  "query":{ 
    "match":{ "name": "zhaoliu" }
  }
}
GET /lib3/user/_search 
{ 
  "query":{ 
    "match":{ "age": 20}
  }
}
#match_all:查询所有文档
GET /ib3/user/_search
{ 
  "query":{"match_all":{}}
}
#multi_match:可以指定多个字段
GET /ib3/user/_search 
{ 
  "query":{ 
    "multi_match": { 
      "query": "Ilyou", 
      "fields": ["interests" ,"name"]
    }
  }
}
#match_ phrase:短语匹配查询
#ElasticSearch引擎首先分析(analyze) 查询字符串,
#从分析后的文本中构建短语查询,
#这意味着必须匹配短语中的所有分词,
#并且保证各个分词的相对位置不变:
GET lib3/user/_search 
{ 
  "query":{
    "match_phrase":{"interests": "duanlian, shuoxiangsheng" }
  }
}

Try a query term, did not find, because the term is not aware of the word, would be "name": "zhaoliu zhaoming" as a keyword in the keyword index inverted index is not, so there is no found

 

 The same query terms do not know word (in inverted index "name": "zhaoliu zhaoming" will be seen as a keyword in the inverted index is an index does not exist) and an array of query terms, does not support a single string query

#match query know the word's Existence, will be filed segmentation operation, and then specify a single query #match query field conditions

GET /lib3/user/_search
{
  "query":{
    "match":{"name": "zhaoliu zhaoming"}
  }
}
{
  "took" : 38,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 2,
    "max_score" : 0.6931472,
    "hits" : [
      {
        "_index" : "lib3",
        "_type" : "user",
        "_id" : "2",
        "_score" : 0.6931472,
        "_source" : {
          "name" : "zhaoming",
          "address" : "bei jing hai dian qu qing he zhen",
          "age" : 20,
          "birthday" : "1998-10-12",
          "interests" : "xi huan hejiu, duanlian, changge"
        }
      },
      {
        "_index" : "lib3",
        "_type" : "user",
        "_id" : "1",
        "_score" : 0.2876821,
        "_source" : {
          "name" : "zhaoliu",
          "address" : "hei long jiang sheng tie ling shi",
          "age" : 50,
          "birthday" : "1970-12-12",
          "interests" : "xi buan hejiu, duanlian, lvyou"
        }
      }
    ]
  }
}

We look at the problem of matching

GET /lib3/user/_search
{
  "query":{
    "match":{"interests": "duanlian changge"}
  }
}
{
  "took" : 8,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 4,
    "max_score" : 1.3862944,
    "hits" : [
      {
        "_index" : "lib3",
        "_type" : "user",
        "_id" : "2",
        "_score" : 1.3862944,
        "_source" : {
          "name" : "zhaoming",
          "address" : "bei jing hai dian qu qing he zhen",
          "age" : 20,
          "birthday" : "1998-10-12",
          "interests" : "xi huan hejiu, duanlian, changge"
        }
      },
      {
        "_index" : "lib3",
        "_type" : "user",
        "_id" : "3",
        "_score" : 0.5753642,
        "_source" : {
          "name" : "lisi",
          "address" : "bei jing hai dian qu qing he zhen",
          "age" : 23,
          "birthday" : "1998-10-12",
          "interests" : "xi huan hejiu,duanlian, changge"
        }
      },
      {
        "_index" : "lib3",
        "_type" : "user",
        "_id" : "5",
        "_score" : 0.2876821,
        "_source" : {
          "name" : "zhangsan",
          "address" : "bei jing chao yang qu",
          "age" : 29,
          "birthday" : "1988-10-12",
          "interests" : "xi huan tingyinyue , changge , tiaowu"
        }
      },
      {
        "_index" : "lib3",
        "_type" : "user",
        "_id" : "1",
        "_score" : 0.2876821,
        "_source" : {
          "name" : "zhaoliu",
          "address" : "hei long jiang sheng tie ling shi",
          "age" : 50,
          "birthday" : "1970-12-12",
          "interests" : "xi buan hejiu, duanlian, lvyou"
        }
      }
    ]
  }
}
#查询user索引下年龄20的文档
GET /lib3/user/_search
{
  "query":{
    "match":{"age": 20}
  }
}
#查询索引user下的所有文档
GET /lib3/user/_search
{
  "query":{
    "match_all":{}
  }
}

#multi_match: You can specify multiple query field conditions

#multi_match指定多个字段条件查询
#只要指定字段条件中含有changge的这个关键字都会被查询出来
#那么含有changge也会被检索到
GET /lib3/user/_search
{
  "query" :{
    "multi_match": {
      "query": "changge",
      "fields": ["interests" , "name"]
    }
  }
}

# Phrase match match_phrase

#短语匹配,在interests这个字段中含有完全一样的短语就会被查询出来
GET lib3/user/_search
{
  "query":{
    "match_phrase":{"interests": "duanlian, changge"}
  }
}

 

 

Published 298 original articles · won praise 107 · Views 140,000 +

Guess you like

Origin blog.csdn.net/ywl470812087/article/details/104875610