Elasticsearch tres consulta básica (la palabra Inglés) coinciden con la consulta

#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" }
  }
}

Pruebe con un término de consulta, no encontró, porque el término no tiene conocimiento de la palabra, sería "name": índice "zhaoliu Zhaoming" como palabra clave en el índice palabra clave no es invertida, para que no haya encontrado

 

 Los mismos términos de la consulta no conocen la palabra (en el índice de "nombre" invertida: "zhaoliu Zhaoming" serán vistos como una palabra clave en el índice invertido es un índice no existe) y una serie de términos de consulta, no es compatible con una sola cuerda pregunta

#match consulta conocen la existencia de la palabra, será presentada la operación de segmentación y especifique una sola consulta las condiciones del campo de consulta #match

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"
        }
      }
    ]
  }
}

Nos fijamos en el problema de la coincidencia

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: Puede especificar varias condiciones de campo consulta

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

# Partido match_phrase Frase

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

 

 

Publicados 298 artículos originales · ganado elogios 107 · Vistas de 140.000 +

Supongo que te gusta

Origin blog.csdn.net/ywl470812087/article/details/104875610
Recomendado
Clasificación