标签:required jni 缓存 form 就会 html verify 多少 top
1 body = { 2 "query": { 3 "match": { 4 "name": "成都" 5 } 6 } 7 } 8 # print(es.search(index="p1", body=body)) 9 print(es.search(index="p1", body=body, filter_path=["hits.hits"])) 10 print(es.search(index="p1", body=body, filter_path=["hits.hits._source"])) 11 print(es.search(index="p1", body=body, filter_path=["hits.hits._source", "hits.total"])) 12 print(es.search(index="p1", body=body, filter_path=["hits.*"])) 13 print(es.search(index="p1", body=body, filter_path=["hits.hits._*"]))
1 # print(es.index(index="p2", doc_type="doc", id=1, body={"name": "棒槌", "age": "18"})) # 正常 2 # print(es.index(index="p2", doc_type="doc", id=2, body={"name": "棒棒哒", "age": 20})) # 正常 3 # print(es.index(index="p2", doc_type="doc", body={"name": "熊大", "age": "10"})) # 如果添加文档不带id自动会创建一个
1 # get(self, index, id, doc_type="_doc", params=None): 2 # print(es.get(index=‘p2‘, doc_type=‘doc‘, id=1)) # 正常 3 # print(es.get(index=‘p2‘, doc_type=‘doc‘)) # TypeError: get() missing 1 required positional argument: ‘id‘ 只能取单个文档对象 4 # print(es.get(index=‘p2‘, id=2)) # 要指定文档类型elasticsearch.exceptions.NotFoundError: NotFoundError(404, ‘{"_index":"p2","_type":"_doc","_id":"2","found":false}‘)
doc_type
要搜索的以逗号分隔的文档类型列表; 留空以对所有类型执行操作。body
使用Query DSL(QueryDomain Specific Language查询表达式)的搜索定义。_source
返回_source
字段的true或false,或返回的字段列表,返回指定字段。_source_exclude
要从返回的_source
字段中排除的字段列表,返回的所有字段中,排除哪些字段。_source_include
从_source
字段中提取和返回的字段列表,跟_source
差不多。1 # print(es.search(index=‘p2‘, body={"query": {"match": {"age": "10"}}})) 2 # print(es.search(index=‘p2‘, body={"query": {"match": {"age": "10"}}}, _source=[‘name‘, ‘age‘])) 3 # print(es.search(index=‘p2‘, body={"query": {"match": {"age": "10"}}}, _source_exclude=[‘age‘])) 4 print(es.search(index=‘p2‘, body={"query": {"match": {"age": "10"}}}, _source_include=[‘age‘]))
排除结果
{‘took‘: 3, ‘timed_out‘: False, ‘_shards‘: {‘total‘: 5, ‘successful‘: 5, ‘skipped‘: 0, ‘failed‘: 0}, ‘hits‘: {‘total‘: 2, ‘max_score‘: 0.2876821, ‘hits‘: [{‘_index‘: ‘p2‘, ‘_type‘: ‘doc‘, ‘_id‘: ‘lEP_u2wBsrL_vQjNIMFf‘, ‘_score‘: 0.2876821, ‘_source‘: {‘name‘: ‘熊大‘}}, {‘_index‘: ‘p2‘, ‘_type‘: ‘doc‘, ‘_id‘: ‘W0MjvGwBsrL_vQjNNd0x‘, ‘_score‘: 0.2876821, ‘_source‘: {‘sex‘: ‘男‘, ‘name‘: ‘熊大‘, ‘desc‘: ‘卡通智障儿童‘}}]}}
1 print(es.get_source(index=‘p2‘, doc_type=‘doc‘, id=‘1‘))
1 body = { 2 "query": { 3 "match": { 4 "age": 18 5 } 6 } 7 } 8 # print(es.count(index=‘p2‘, doc_type=‘doc‘, body=body)) 9 # print(es.count(index=‘p2‘, doc_type=‘doc‘, body=body)[‘count‘]) 10 print(es.count(index=‘p2‘)) # 查在p2索引中总的文档个数{‘count‘: 4, ‘_shards‘: {‘total‘: 5, ‘successful‘: 5, ‘skipped‘: 0, ‘failed‘: 0}} 11 print(es.count(index=‘p2‘, doc_type=‘doc‘)) # {‘count‘: 4, ‘_shards‘: {‘total‘: 5, ‘successful‘: 5, ‘skipped‘: 0, ‘failed‘: 0}}
1 # print(es.create(index=‘p2‘, doc_type=‘doc‘, id=3, body={"city": "成都", "desc": "旅游的地方颇多, 小吃出名"})) 2 print(es.get_source(index=‘p2‘, doc_type=‘doc‘, id=3))
1 # print(es.delete(index=‘p2‘, doc_type=‘doc‘, id=1)) 2 # print(es.delete_by_query(index=‘p2‘, body={"query": {"match": {"age": 20}}})) 3 # print(es.search(index=‘p2‘))
1 print(es.exists(index=‘p2‘, doc_type=‘doc‘, id=‘1‘))
1 print(es.info())
1 print(es.ping())
创建索引
1 body = { 2 "mappings": { 3 "doc": { 4 "dynamic": "strict", 5 "properties": { 6 "title": { 7 "type": "text", 8 "analyzer": "ik_max_word" 9 }, 10 "url": { 11 "type": "text" 12 }, 13 "action_type": { 14 "type": "text" 15 }, 16 "content": { 17 "type": "text" 18 } 19 } 20 } 21 } 22 } 23 24 print(es.indices.create(index=‘p3‘, body=body))
创建结果
1 {‘acknowledged‘: True, ‘shards_acknowledged‘: True, ‘index‘: ‘p3‘}
1 print(es.indices.analyze(body={‘analyzer‘: ‘ik_max_word‘, ‘text‘: "皮特和茱丽当选“年度模范情侣”Brad Pitt and Angelina Jolie"}))
1 print(es.indices.delete(index=‘p3‘)) 2 print(es.indices.delete(index=‘p2‘)) # {‘acknowledged‘: True}
1 print(es.indices.put_alias(index=‘p3‘, name=‘p3_alias‘)) # 为单个索引创建别名 2 print(es.indices.put_alias(index=[‘p3‘, ‘p2‘], name=‘p23_alias‘)) # 为多个索引创建同一个别名,联查用
1 print(es.indices.delete_alias(index=‘p1‘)) 2 print(es.indices.delete_alias(index=[‘p1, p2‘]))
1 print(es.indices.get_mapping(index=‘p3‘))
1 print(es.indices.get_settings(index=‘p3‘))
1 print(es.indices.get(index=‘p2‘)) # 查询指定索引是否存在 2 print(es.indices.get(index=[‘p2‘, ‘p3‘]))
1 print(es.indices.get_alias(index=‘p2‘)) 2 print(es.indices.get_alias(index=[‘p2‘, ‘p3‘]))
1 print(es.indices.get_field_mapping(fields=‘url‘, index=‘p3‘, doc_type=‘doc‘)) 2 print(es.indices.get_field_mapping(fields=[‘url‘, ‘title‘], index=‘p3‘, doc_type=‘doc‘))
1 print(es.cluster.get_settings())
1 print(es.cluster.health())
1 print(es.cluster.state())
1 print(es.cluster.stats())
1 print(es.nodes.info()) # 返回所节点 2 print(es.nodes.info(node_id=‘node1‘)) # 指定一个节点 3 print(es.nodes.info(node_id=[‘node1‘, ‘node2‘])) # 指定多个节点列表
1 print(es.nodes.stats()) 2 print(es.nodes.stats(node_id=‘node1‘)) 3 print(es.nodes.stats(node_id=[‘node1‘, ‘node2‘]))
1 print(es.nodes.hot_threads(node_id=‘node1‘)) 2 print(es.nodes.hot_threads(node_id=[‘node1‘, ‘node2‘]))
1 print(es.nodes.usage()) 2 print(es.nodes.usage(node_id=‘node1‘)) 3 print(es.nodes.usage(node_id=[‘node1‘, ‘node2‘]))
1 print(es.cat.aliases(name=‘p23_alias‘)) 2 print(es.cat.aliases(name=‘p23_alias‘, format=‘json‘))
1 print(es.cat.allocation()) 2 print(es.cat.allocation(node_id=[‘node1‘])) 3 print(es.cat.allocation(node_id=[‘node1‘, ‘node2‘], format=‘json‘))
1 print(es.cat.count()) # 集群内的文档总数 2 print(es.cat.count(index=‘p3‘)) # 指定索引文档总数 3 print(es.cat.count(index=[‘p3‘, ‘p2‘], format=‘json‘)) # 返回两个索引文档和
es.cat.fielddata,基于每个节点显示有关当前加载的fielddata的信息。有些数据为了查询效率,会放在内存中,fielddata用来控制哪些数据应该被放在内存中,而这个es.cat.fielddata则查询现在哪些数据在内存中,数据大小等信息。
1 print(es.cat.fielddata()) 2 print(es.cat.fielddata(format=‘json‘, bytes=‘b‘))
1 bytes 单位‘b‘,‘k‘,‘kb‘,‘m‘,‘mb‘,‘g‘,‘gb‘,‘t‘,‘tb‘ ,‘p‘,‘pb‘
1 print(es.cat.health()) 2 print(es.cat.health(format=‘json‘))
1 print(es.cat.help())
1 print(es.cat.indices()) 2 print(es.cat.indices(index=‘p3‘)) 3 print(es.cat.indices(index=‘p3‘, format=‘json‘))
1 print(es.cat.master()) 2 print(es.cat.master(format=‘json‘))
1 print(es.cat.nodeattrs()) 2 print(es.cat.nodeattrs(format=‘json‘))
1 print(es.cat.nodes()) 2 print(es.cat.nodes(format=‘json‘))
1 print(es.cat.plugins()) 2 print(es.cat.plugins(format=‘json‘))
1 print(es.cat.segments()) 2 print(es.cat.segments(index=‘p3‘)) 3 print(es.cat.segments(index=‘p3‘, format=‘json‘))
1 print(es.cat.shards()) 2 print(es.cat.shards(index=‘p3‘)) 3 print(es.cat.shards(index=‘p3‘, format=‘json‘))
1 print(es.cat.thread_pool())
更多玩法https://elasticsearch-py.readthedocs.io/en/master/api.html
标签:required jni 缓存 form 就会 html verify 多少 top
原文地址:https://www.cnblogs.com/Alexephor/p/11398060.html