ElasticSearch25:初识搜索引擎_快速掌握query string search语法以及_all metadata原理揭秘

1.query string search语法

就是将请求的条件加到string的后面,同时也需要掌握+-的原理

搜索test_field中包含hangzhou的数据

GET /test_index/test_type/_search?q=test_field:hangzhou

{
  "took": 9,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 1,
    "max_score": 0.9808292,
    "hits": [
      {
        "_index": "test_index",
        "_type": "test_type",
        "_id": "2",
        "_score": 0.9808292,
        "_source": {
          "test_field": "hangzhou"
        }
      }
    ]
  }
}


搜索test_field中必须包含hangzhou的数据

GET /test_index/test_type/_search?q=+test_field:hangzhou

{
  "took": 9,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 1,
    "max_score": 0.9808292,
    "hits": [
      {
        "_index": "test_index",
        "_type": "test_type",
        "_id": "2",
        "_score": 0.9808292,
        "_source": {
          "test_field": "hangzhou"
        }
      }
    ]
  }
}


搜索test_field必须不包含hangzhou的数据

GET /test_index/test_type/_search?q=-test_field:hangzhou

{
  "took": 17,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 11,
    "max_score": 1,
    "hits": [
      {
        "_index": "test_index",
        "_type": "test_type",
        "_id": "5",
        "_score": 1,
        "_source": {
          "test_field": "taizhou"
        }
      },
      {
        "_index": "test_index",
        "_type": "test_type",
        "_id": "8",
        "_score": 1,
        "_source": {
          "test_field": "jiaxing"
        }
      },
      {
        "_index": "test_index",
        "_type": "test_type",
        "_id": "9",
        "_score": 1,
        "_source": {
          "test_field": "zhoushan"
        }
      },
      {
        "_index": "test_index",
        "_type": "test_type",
        "_id": "10",
        "_score": 1,
        "_source": {
          "test_field": "lishui"
        }
      },
      {
        "_index": "test_index",
        "_type": "test_type",
        "_id": "12",
        "_score": 1,
        "_source": {
          "test_field": "jinhua"
        }
      },
      {
        "_index": "test_index",
        "_type": "test_type",
        "_id": "4",
        "_score": 1,
        "_source": {
          "test_field": "ningbo"
        }
      },
      {
        "_index": "test_index",
        "_type": "test_type",
        "_id": "6",
        "_score": 1,
        "_source": {
          "test_field": "quzhou"
        }
      },
      {
        "_index": "test_index",
        "_type": "test_type",
        "_id": "1",
        "_score": 1,
        "_source": {
          "test_field": "zhejiang"
        }
      },
      {
        "_index": "test_index",
        "_type": "test_type",
        "_id": "7",
        "_score": 1,
        "_source": {
          "test_field": "huzhou"
        }
      },
      {
        "_index": "test_index",
        "_type": "test_type",
        "_id": "3",
        "_score": 1,
        "_source": {
          "test_field": "wenzhou"
        }
      }
    ]
  }
}






2._all metadata的原理及作用

搜索所有的field,任意一个field包含关键词,就可以搜索出来

GET /test_index/test_type/_search?q=hangzhou


我们在进行搜索 时候,难道是对document中的每一个field都进行一次搜索吗?

不是的。es的_all元数据,在建立索引的时候,我们插入一个document,它里面包含了多各field,此时,es会自动将多个field的值,全部用字符串的方式串连起来,变成一个长的字符串,作为_all field的值,同时建立索引。

后面如果在搜索的时候,没有对某个field指定搜索,就默认搜索_all field ,其中是包含了所有field的值。

例如

{

"name":"jack",

"age":26,

"email":"jack@mail.com",

"address":"zhejiang"

}

那么插入这条数据的时候,es会向_all中插入jack 26 jack@mail.com zhejiang,同时分词后建立倒排索引

以上就是_all metadata的作用








评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值