elasticsearch学习笔记(二十四)——Elasticsearch query string语法以及_all元数据原理

栏目: 后端 · 发布时间: 6年前

内容简介:对于query string只要掌握q=field:search content的语法,以及+和-的含义+:代表包含这个筛选条件结果-:代表不包含这个筛选条件的结果

1、query string 语法

GET /test_index/_search?q=test_field1:update
GET /test_index/_search?q=+test_field1:update

{
  "took" : 7,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : 0.2876821,
    "hits" : [
      {
        "_index" : "test_index",
        "_type" : "_doc",
        "_id" : "3",
        "_score" : 0.2876821,
        "_source" : {
          "test_field1" : "update test1",
          "test_field2" : "update test2"
        }
      }
    ]
  }
}

GET /test_index/_search?q=-test_field1:update
{
  "took" : 12,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 7,
      "relation" : "eq"
    },
    "max_score" : 0.0,
    "hits" : [
      {
        "_index" : "test_index",
        "_type" : "_doc",
        "_id" : "10",
        "_score" : 0.0,
        "_source" : {
          "test_field" : "test10 routing _id"
        }
      },
      {
        "_index" : "test_index",
        "_type" : "_doc",
        "_id" : "7",
        "_score" : 0.0,
        "_routing" : "2",
        "_source" : {
          "test_field1" : "test1"
        }
      },
      {
        "_index" : "test_index",
        "_type" : "_doc",
        "_id" : "2",
        "_score" : 0.0,
        "_source" : {
          "test_field" : "test client 1",
          "name" : "test1"
        }
      },
      {
        "_index" : "test_index",
        "_type" : "_doc",
        "_id" : "1",
        "_score" : 0.0,
        "_source" : {
          "test_field" : "test test",
          "name" : "test1"
        }
      },
      {
        "_index" : "test_index",
        "_type" : "_doc",
        "_id" : "7",
        "_score" : 0.0,
        "_routing" : "1",
        "_source" : {
          "test_field1" : "test1"
        }
      },
      {
        "_index" : "test_index",
        "_type" : "_doc",
        "_id" : "11",
        "_score" : 0.0,
        "_routing" : "12",
        "_source" : {
          "test_field" : "test routing not _id"
        }——
      },
      {
        "_index" : "test_index",
        "_type" : "_doc",
        "_id" : "20",
        "_score" : 0.0,
        "_source" : {
          "test_field" : "test consistency"
        }
      }
    ]
  }
}

对于query string只要掌握q=field:search content的语法,以及+和-的含义

+:代表包含这个筛选条件结果

-:代表不包含这个筛选条件的结果

2、_all metadata

也就是在使用query string的时候,如果不指定field,那么默认就是_all。_all元数据是在建立索引的时候产生的,我们插入一条document,它里面包含了多个field,此时ES会自动将多个field的值全部用字符串的方式串联起来,变成一个长的字符串。这个长的字符串就是_all field的值。同时建立索引。

举个例子:

对于一个document:

{
    "name": "jack",
    "age": 26,
    "email": "jack@sina.com",
    "address": "guamazhou"
}

那么"jack 26 jack@sina.com guamazhou",就会作为这个document的_all fieldd的值,同时进行分词后建立对应的倒排索引。

注意在生产环境中一般不会使用query string这种查询方式。


以上所述就是小编给大家介绍的《elasticsearch学习笔记(二十四)——Elasticsearch query string语法以及_all元数据原理》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

正当法律程序简史

正当法律程序简史

(美)约翰·V.奥尔特 / 杨明成、陈霜玲 / 商务印书馆 / 2006-8 / 14.00元

本书的主题——正当法律程序,是英美法的核心概念,它使诸如法治、经济自由、个人自治以及免于政府专断行为的侵害等价值观念具体化,因而是法学领域一个永恒的主题,数百年以来一直是法学家、法官及律师关注的重点。本书以极为简洁、精确的语言总结了五百年法律发展的恢弘历史,为人们描述了正当法律程序观念发展演变的清晰轨迹。而沿着这条轨迹,人们可以准确地了解正当法律程序这一重要概念所包含的广泛的问题。 作为一本......一起来看看 《正当法律程序简史》 这本书的介绍吧!

URL 编码/解码
URL 编码/解码

URL 编码/解码

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具