ElasticSearchAPI操作

查看Es节点信息

http://10.1.22.23:9200/_nodes?pretty

http://192.168.0.75:9200/_nodes/stats?pretty

测试Es的分词

POST _analyze
{ 
    "analyzer":"index_ansj”, 
    "text":"十堰市红十字医院”  
} 
POST _analyze 
{ 
    "analyzer":"query_ansj”, 
    "text":"十堰市红十字医院”  
}


直接指定索引中的字段进行测试
post index_name/_analyze
 
{
   "field":"firtname", #要进行分析的索引中的字段
   "text":"ni cai" #要进行分析的文本 
}

自定义分词器进行测试
post _analyze
 
{
   "tokenizer":"standard", #指定的分词器
   "filter":["lowercase"],  #对分析后的词最后进行小写转换
   "text":"hello world" #要进行分析的文本
 
}

新旧索引导数据

POST _reindex

{
  "source": {
    "index": "sphinx-doctor_20190515-19:53:24"   #旧索引
  },
  "dest": {
    "index": "sphinx-doctor_20190614-16:15:07"   #新索引
  }
}

分析底层查询逻辑

GET sphinx-doctor/_validate/query?explain
{
  "query": {
    "bool": {
      "should": {
        "match": {
          "hospitalname": {
            "query": "滨州市"
          }
        }
      }
    }
  }
}

结果:
{
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "failed" : 0
  },
  "valid" : true,
  "explanations" : [
    {
      "index" : "sphinx-doctor-19.07.12-144934",
      "valid" : true,
      "explanation" : "(hospitalname:滨州市 hospitalname:滨州 hospitalname:滨 hospitalname:州市 hospitalname:州 hospitalname:市)"
    }
  ]
}

新建索引别名

POST _aliases
{
  "actions": [
    {
      "add": {
        "index": "sphinx-doctor-19.07.12-144934",
        "alias": "sphinx-doctor"
      }
    }
  ]
}

删除索引别名

POST / _aliases {
    "actions": [{
        "remove": {
            "index": "sphinx-doctor-19.07.12-144934",
            "alias": "sphinx-doctor"
        }
    }]
}

重新命名别名

POST /_aliases
{
    "actions": [
        {"remove": {"index": "test1", "alias": "alias1"}},
        {"add": {"index":"test1", "alias": "alias2"}}
    ]
}

 

 

禁止索引对分片的分配

curl -X PUT http://0.0.0.0:9200/_cluster/settings?pretty -d '{"transient": {"cluster.routing.allocation.enable": "none"}}' 

开启索引分片的分配

curl -X PUT http://0.0.0.0:9200/_cluster/settings?pretty -d '{"transient":{"cluster.routing.allocation.enable":"all"}}

注意:新建索引的过程要分片,禁用了分配分片,自然也就无法新建索引。已经分配了分片只是不能再在节点之间迁移,不会影响读写。集群重启的时候关闭allocation,是为了防止节点重启时节点上的分片被重新分配,这个过程很耗费资源,而且重启是很快完成的,当集群快速重启后,其上的分片大部分是可以直接分配来用的,这样也就可以加速集群完成分片的速度,从而加速重启的速度。禁用或者不禁用allocation都不会影响业务,只是可能由于节点下线的时候由于分片重新分配导致es状态由yello到green的时间变长,从而导致重启时间边长。

 

查看集群状态

http://192.168.0.75:9200/_cluster/state?pretty

查看集群统计

http://192.168.0.75:9200/_cluster/stats?pretty

返回一个正在添加到更新集群状态的列表

http://192.168.0.75:9200/_cluster/tasks?pretty

查看account索引的映射结构:

http://192.168.0.171:9200/account/_mappings?pretty  

6.查看account索引的配置信息

http://192.168.0.77:9200/account/_settings?pretty

7.查看集群健康状态信息

http://192.168.0.75:9200/_cluster/health?pretty

查询某一索引:
http://192.168.0.75:9200/_cluster/health/sphinx-faculty?pretty

8.查看集群状态信息

http://192.168.0.75:9200/_cluster/health?pretty

9.查看es磁盘信息

http://192.168.0.75:9200/_cat/allocation?v&pretty

10.查看索引状态信息

http://192.168.0.75:9200/_stats

11.查看设置

http://192.168.0.75:9200/_all/_settings

12.查看索引内容

http://192.168.0.75:9200/account/_search

13.查看es集群副本分配节点

http://192.168.0.75:9200/_cat/shards?v

14.查看每个索引的健康状况

http://127.0.0.1:9200/_cat/indices?v

15.查看节点信息

http://127.0.0.1:9200/_cat/nodes?v

16.查看各个分片上索引的信息

http://127.0.0.1:9200/_cat/shards?v

17查看某一个doc的某个字段的分词情况

http://127.0.0.1:9200/sphinx-doctorinfo/doctorinfo/6841/_termvectors?fields=diseaseIds
http://127.0.0.1:9200/sphinx-drugcatalogue/drugcatalogue/5351147363/_termvectors?fields=*

注:
GET index/type/id/_termvectors?fields=fieldsName

term的基本信息:

  •  term_freq:term在该字段中的频率
  •  position:词在该字段中的位置
  •  start_offset:从什么偏移量开始的
  •  end_offset: 到什么偏移量结束

term的统计信息:如果启用了term的统计信息,即term_statistics设为true

  •  doc_freq: 该词在文档中出现的频率
  •  ttf:total term frequency的缩写,一个term在所有document中出现的频率

字段的统计信息:如果启用了字段统计信息,即field_statistics设为true

  •  sum_doc_freq: 一个field中所有term的df之和
  •  doc_count: 有多少个文档包含这个字段
  •  sum_ttf:sum total term frequency的缩写, 一个field中的所有term的tf之和
  • term statistics和field statistics并不精准,不会被考虑有的doc可能被删除了

18.验证分词器的实现状况

http://127.0.0.1:9200/sphinx-doctorinfo/_analyze?analyzer=comma&text=2,3,4,5,100-100


"diseaseIds": {
    "type": "string",
    "analyzer": "comma",
    "search_analyzer": "comma"
}



"analysis": {
	"analyzer": {
		"index_ansj_syno": {
			"type": "custom",
			"tokenizer": "index_ansj",
			"filter": "synonym"
		},
		"comma": {
			"type": "pattern",
			"pattern": ","
		}
	}
}

 

20.查看索引的setting

GET:http://127.0.0.1:9200/sphinx-hospitalfaculty/_settings?preserve_existing=true

{
	"sphinx-hospitalfaculty_20190605-15:41:33": {
		"settings": {
			"index": {
				"refresh_interval": "30s",
				"number_of_shards": "10",
				"translog": {
					"flush_threshold_ops": "100000"
				},
				"similarity": {
					"BM25_title": {
						"type": "BM25",
						"b": "0.2",
						"k1": "0"
					},
					"my_BM25": {
						"type": "BM25",
						"b": "0",
						"k1": "1.0"
					}
				},
				"index": {
					"max_result_window": "10000"
				},
				"creation_date": "1559720492916",
				"analysis": {
					"analyzer": {
						"index_ansj_syno": {
							"filter": "synonym",
							"type": "custom",
							"tokenizer": "index_ansj"
						}
					}
				},
				"number_of_replicas": "1",
				"uuid": "9EnuxeYuQUyQkeYRPawK-Q",
				"version": {
					"created": "2030599"
				}
			}
		}
	}
}

20.修改索引的max_result_window

PUT:http://127.0.0.1:9200/sphinx-hospitalfaculty/_settings?preserve_existing=true

{
  "max_result_window": "2000000000"
}

响应:
{
	"acknowledged": true
}

 

 

 

 

转载于:https://my.oschina.net/u/3727895/blog/3034508

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值