Elasticsearch consulta básica dos (Inglés palabra) plazo y los términos de la consulta

plazo y términos consultas (Encontrar zhaoliu la información de esta persona)
Término de consulta irá al arco índice invertido | para encontrar el término exacto, no se sabe la existencia de la palabra. Tal consulta de palabras clave, fecha numérica ..
Plazo: consulta un campo contiene una documentación palabra clave
GET / lib3 / usuario / _search / { "consulta": { "término": {intereses ":" Changge "} }}
Condiciones: un campo de consulta con una pluralidad de palabras clave unidas documento
GET / IB3 / usuario / _search { "Query": { "términos ': {" intereses ": [" hejiu "" Changge']}}

GET /lib3/user/_search
{
  "query": {
    "term": {
      "name": {
        "value": "zhaoliu"
      }
    }
  }
}
 
 
GET /lib3/user/_search
{
  "query": {
    "term": {
      "name": "zhaoliu"
    }
  }
}
{
  "took" : 5,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 1,
    "max_score" : 0.2876821,
    "hits" : [
      {
        "_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"
        }
      }
    ]
  }
}


 

Encuentra aficiones intereses del pueblo como la información hejiu Changge

GET /lib3/user/_search
{
  "query": {
    "terms": {
      "interests": ["hejiu","changge"]
    }
  }
}
{
  "took" : 56,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 4,
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "lib3",
        "_type" : "user",
        "_id" : "5",
        "_score" : 1.0,
        "_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" : "2",
        "_score" : 1.0,
        "_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" : 1.0,
        "_source" : {
          "name" : "zhaoliu",
          "address" : "hei long jiang sheng tie ling shi",
          "age" : 50,
          "birthday" : "1970-12-12",
          "interests" : "xi buan hejiu, duanlian, lvyou"
        }
      },
      {
        "_index" : "lib3",
        "_type" : "user",
        "_id" : "3",
        "_score" : 1.0,
        "_source" : {
          "name" : "lisi",
          "address" : "bei jing hai dian qu qing he zhen",
          "age" : 23,
          "birthday" : "1998-10-12",
          "interests" : "xi huan hejiu,duanlian, changge"
        }
      }
    ]
  }
}


Siempre que contenga una consulta de palabras clave va a estar fuera de un total de cuatro personas tienen acerca hejiu Changge ya sea uno o ambos Changge hejiu

Si sólo quiero tomar los dos primeros de uso personal: 0 (comienza desde el primer documento) tamaño: 2 (Take 2 documentos)

GET /lib3/user/_search
{
  "from":0,
  "size":2,
  "query": {
    "terms": {
      "interests": ["hejiu","changge"]
    }
  }
}
{
  "took" : 81,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 4,
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "lib3",
        "_type" : "user",
        "_id" : "5",
        "_score" : 1.0,
        "_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" : "2",
        "_score" : 1.0,
        "_source" : {
          "name" : "zhaoming",
          "address" : "bei jing hai dian qu qing he zhen",
          "age" : 20,
          "birthday" : "1998-10-12",
          "interests" : "xi huan hejiu, duanlian, changge"
        }
      }
    ]
  }
}


La consulta anterior hay número de versión queremos obtener el número de versión, basta con añadir una versión: true

GET /lib3/user/_search
{
  "version": true, 
  "query": {
    "terms": {
      "interests": ["hejiu","changge"]
    }
  }
}
{
  "took" : 33,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 4,
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "lib3",
        "_type" : "user",
        "_id" : "5",
        "_version" : 1,
        "_score" : 1.0,
        "_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" : "2",
        "_version" : 1,
        "_score" : 1.0,
        "_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",
        "_version" : 1,
        "_score" : 1.0,
        "_source" : {
          "name" : "zhaoliu",
          "address" : "hei long jiang sheng tie ling shi",
          "age" : 50,
          "birthday" : "1970-12-12",
          "interests" : "xi buan hejiu, duanlian, lvyou"
        }
      },
      {
        "_index" : "lib3",
        "_type" : "user",
        "_id" : "3",
        "_version" : 1,
        "_score" : 1.0,
        "_source" : {
          "name" : "lisi",
          "address" : "bei jing hai dian qu qing he zhen",
          "age" : 23,
          "birthday" : "1998-10-12",
          "interests" : "xi huan hejiu,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/104875333
Recomendado
Clasificación