elasticsearch2.1.0 curl 相关操作命令(二)

(1)查看gb索引下的tweet类型的所有字段的映射
curl -XGET 'http://10.4.30.151:9200/gb/_mapping/tweet?pretty'
curl -XGET 'http://10.4.30.151:9200/my_store/_mapping/products?pretty'
curl -XGET 'http://10.4.30.151:9200/megacorp/_mapping/employee?pretty'
可以为已存在的mapping添加一个属性,不需要列出已存在的其他属性。但是不能修改一个已经存在的属性
curl -XPUT 'http://10.4.30.151:9200/megacorp/_mapping/employee?pretty' -H 'Content-Type: application/json' -d'{
  "properties" : {
    "yujie_tag" : {
      "type" :    "string",
      "index":    "not_analyzed"
    }
  }
}'

性能差异编辑
过滤查询(Filtering queries)只是简单的检查包含或者排除,这就使得计算起来非常快。
考虑到至少有一个过滤查询(filtering query)的结果是 “稀少的”(很少匹配的文档),
并且经常使用不评分查询(non-scoring queries),结果会被缓存到内存中以便快速读取,
所以有各种各样的手段来优化查询结果。

相反,评分查询(scoring queries)不仅仅要找出 匹配的文档,还要计算每个匹配文档的相关性,
计算相关性使得它们比不评分查询费力的多。同时,查询结果并不缓存。

多亏倒排索引(inverted index),一个简单的评分查询在匹配少量文档时可能与一个涵盖百万文
档的filter表现的一样好,甚至会更好。但是在一般情况下,一个filter 会比一个评分的query性能更优异,
并且每次都表现的很稳定。

过滤(filtering)的目标是减少那些需要通过评分查询(scoring queries)进行检查的文档。


如何选择查询与过滤编辑
通常的规则是,使用 查询(query)语句来进行 全文 搜索或者其它任何需要影响 相关性得分 的搜索。除此以外的情况都使用过滤(filters)。


(2)批量插入
curl -XPOST 'http://10.4.30.151:9200/my_store/products/_bulk?pretty' -H 'Content-Type: application/json' -d'{ "index": { "_id": 1 }}
{ "price" : 10, "productID" : "XHDK-A-1293-#fJ3" }
{ "index": { "_id": 2 }}
{ "price" : 20, "productID" : "KDKE-B-9947-#kL5" }
{ "index": { "_id": 3 }}
{ "price" : 30, "productID" : "JODL-X-1937-#pV7" }
{ "index": { "_id": 4 }}
{ "price" : 30, "productID" : "QQPX-R-3956-#aD8" }
'

(3)term 精确查询 term 查询只对倒排索引的词项精确匹配,这点很重要,它不会对词的多样性进行处理(如, foo 或 FOO )
curl -XGET 'http://10.4.30.151:9200/my_store/products/_search?pretty' -H 'Content-Type: application/json' -d'{
    "query" : {
        "constant_score" : { 
            "filter" : {
                "term" : { 
                    "price" : 20
                }
            }
        }
    }
}'



(4)嵌套查询
curl -XGET 'http://10.4.30.151:9200/my_store/products/_search?pretty' -H 'Content-Type: application/json' -d'{
   "query" : {
      "filtered" : { 
         "filter" : {
            "bool" : {
              "should" : [
                 { "term" : {"price" : 20}}, 
                 { "term" : {"productID" : "XHDK-A-1293-#fJ3"}} 
              ],
              "must_not" : {
                 "term" : {"price" : 30} 
              }
           }
         }
      }
   }
}'

(5)range 用于查询一定范围的文本
curl -XGET 'http://10.4.30.151:9200/my_store/products/_search?pretty' -H 'Content-Type: application/json' -d'{
    "query" : {
        "constant_score" : {
            "filter" : {
                "range" : {
                    "price" : {
                        "gte" : 20,
                        "lt"  : 40
                    }
                }
            }
        }
    }
}'

全文搜索
全文搜索两个最重要的方面是:

相关性(Relevance)
它是评价查询与其结果间的相关程度,并根据这种相关程度对结果排名的一种能力,
这种计算方式可以是 TF/IDF 方法(参见 相关性的介绍)、地理位置邻近、模糊相似,或其他的某些算法。

分析(Analysis)
它是将文本块转换为有区别的、规范化的 token 的一个过程,(参见 分析的介绍) 目的是为了(a)创建倒排索引以及(b)查询倒排索引。

 match 查询主要的应用场景就是进行全文搜索
 

(6)批量插入 
curl -XPOST 'http://10.4.30.151:9200/my_index/my_type/_bulk?pretty' -H 'Content-Type: application/json' -d'{"index": { "_id": 1 }}
{ "title": "The quick brown fox" }
{ "index": { "_id": 2 }}
{ "title": "The quick brown fox jumps over the lazy dog" }
{ "index": { "_id": 3 }}
{ "title": "The quick brown fox jumps over the quick dog" }
{ "index": { "_id": 4 }}
{ "title": "Brown fox brown dog" }'

curl -XGET 'http://10.4.30.151:9200/my_index/my_type/_search?pretty' -H 'Content-Type: application/json' -d'{
    "query": {
        "match": {
            "title": "QUICK!"
        }
    }
}'

match 多词查询
不去匹配 brown OR dog ,而通过匹配 brown AND dog 找到所有文档
curl -XGET 'http://10.4.30.151:9200/my_index/my_type/_search?pretty' -H 'Content-Type: application/json' -d'{
    "query": {
        "match": {
            "title": {      
                "query":    "BROWN DOG!",
                "operator": "and"
            }
        }
    }
}'









评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值