文档章节

elaselasticsearch2.3 python search超时bug

 张欢19933
发布于 2017/08/17 13:44
字数 886
阅读 23
收藏 0
点赞 0
评论 0

本地安装elasticsearch python包

pip install elasticsearch==2.3.0

注意指明版本号

建立连接

from elasticsearch import Elasticsearch
es = Elasticsearch()
或
es = Elasticsearch(
    [
        'ip1:9200','ip2:9200'
    ]
)

不指明ip和端口号,默认连接本地9200端口,连接多台可以保证高可用

执行操作

特别说明search操作

官网函数说明

search(*args, **kwargs)
Execute a search query and get back search hits that match the query. http://www.elastic.co/guide/en/elasticsearch/reference/current/search-search.html

Parameters:	
index – A comma-separated list of index names to search; use _all or empty string to perform the operation on all indices

doc_type – A comma-separated list of document types to search; leave empty to perform the operation on all types

body – The search definition using the Query DSL

_source – True or false to return the _source field or not, or a list of fields to return

_source_exclude – A list of fields to exclude from the returned _source field

_source_include – A list of fields to extract and return from the _source field

allow_no_indices – Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes _all string or when no indices have been specified)

analyze_wildcard – Specify whether wildcard and prefix queries should be analyzed (default: false)

analyzer – The analyzer to use for the query string

default_operator – The default operator for query string query (AND or OR), default ‘OR’, valid choices are: ‘AND’, ‘OR’

df – The field to use as default where no field prefix is given in the query string

expand_wildcards – Whether to expand wildcard expression to concrete indices that are open, closed or both., default ‘open’, valid choices are: ‘open’, ‘closed’, ‘none’, ‘all’

explain – Specify whether to return detailed information about score computation as part of a hit

fielddata_fields – A comma-separated list of fields to return as the field data representation of a field for each hit

fields – A comma-separated list of fields to return as part of a hit

from_ – Starting offset (default: 0)

ignore_unavailable – Whether specified concrete indices should be ignored when unavailable (missing or closed)

lenient – Specify whether format-based query failures (such as providing text to a numeric field) should be ignored

lowercase_expanded_terms – Specify whether query terms should be lowercased

preference – Specify the node or shard the operation should be performed on (default: random)

q – Query in the Lucene query string syntax

request_cache – Specify if request cache should be used for this request or not, defaults to index level setting

routing – A comma-separated list of specific routing values

scroll – Specify how long a consistent view of the index should be maintained for scrolled search

search_type – Search operation type, valid choices are: ‘query_then_fetch’, ‘dfs_query_then_fetch’, ‘count’, ‘scan’

size – Number of hits to return (default: 10)

sort – A comma-separated list of <field>:<direction> pairs

stats – Specific ‘tag’ of the request for logging and statistical purposes

suggest_field – Specify which field to use for suggestions

suggest_mode – Specify suggest mode, default ‘missing’, valid choices are: ‘missing’, ‘popular’, ‘always’

suggest_size – How many suggestions to return in response

suggest_text – The source text for which the suggestions should be returned

terminate_after – The maximum number of documents to collect for each shard, upon reaching which the query execution will terminate early.

timeout – Explicit operation timeout

track_scores – Whether to calculate and return scores even if they are not used for sorting

version – Specify whether to return document version as part of a hit

代码

rs = es.search(index=index,body=body,size=0,timeout="60s")

当我们执行search的时候会报read timeout的错误

Traceback (most recent call last):
  File "es_test.py", line 39, in <module>
    rs = es.search(index=index,body=body,size=0,timeout="60s")
  File "/home/xiaoju/weijian/anaconda2/lib/python2.7/site-packages/elasticsearch/client/utils.py", line 69, in _wrapped
    return func(*args, params=params, **kwargs)
  File "/home/xiaoju/weijian/anaconda2/lib/python2.7/site-packages/elasticsearch/client/__init__.py", line 548, in search
    doc_type, '_search'), params=params, body=body)
  File "/home/xiaoju/weijian/anaconda2/lib/python2.7/site-packages/elasticsearch/transport.py", line 329, in perform_request
    status, headers, data = connection.perform_request(method, url, params, body, ignore=ignore, timeout=timeout)
  File "/home/xiaoju/weijian/anaconda2/lib/python2.7/site-packages/elasticsearch/connection/http_urllib3.py", line 102, in perform_request
    raise ConnectionTimeout('TIMEOUT', str(e), e)
elasticsearch.exceptions.ConnectionTimeout: ConnectionTimeout caused by - ReadTimeoutError(HTTPConnectionPool(host='bigdata-ara-ser200.gz01', port=8200): Read timed out. (read timeout=10))

我们明明设置了timeout为60s,为什么报错显示为10s,timeout为什么没有生效,我百思不得其解,后来我按照报错在源码包里的位置找到对应的函数

如图所示,它取得是request_timeout这个参数,但是search这个函数的参数里却只有timeout这个参数,估计是官网没有更新这个bug,然后我们修改代码

rs = es.search(index=index,body=body,size=0,request_timeout=60)

这时候我们发现运行成功。

更多api请查看

http://elasticsearch-py.readthedocs.io/en/2.3.0/api.html#elasticsearch

© 著作权归作者所有

共有 人打赏支持
粉丝 29
博文 422
码字总数 211998
作品 0
海淀
最新阿里巴巴面试题(附带面试标准答案)

在上一节中,我们已经介绍了关于阿里巴巴的任职要求,这节我就详细的介绍一下关于阿里巴巴的面试题(涉及到标准代码部分不予以出现,如果想要可以加群:725479218,里面可以进行技术分享、技术...

柯西带你学编程 ⋅ 06/02 ⋅ 0

python 爬虫urllib基础示例

环境使用python3.5.2 urllib3-1.22 下载安装 wget https://www.python.org/ftp/python/3.5.2/Python-3.5.2.tgz tar -zxf Python-3.5.2.tgz cd Python-3.5.2/ ./configure --prefix=/usr/loc......

super李导 ⋅ 05/30 ⋅ 0

Python测试远程端口连接时间

人生苦短 我用Python 问题 最近自己服务器访问别人的服务器,有时候会报超时错误,有时候又能够正常访问别人服务器。 思路 最开始猜测是网络不稳定造成的,但是自己没有收集什么时候超时,什...

亚林瓜子 ⋅ 05/10 ⋅ 0

pip的安装及其使用

安装: Python3 :apt-get install python3-pip Python2 : apt-get install python2-pip 查看版本信息: python3 -m pip -V pip 8.1.1 from /usr/lib/python3/dist-packages (python 3.5) p......

Bony ⋅ 2016/10/29 ⋅ 0

利用python进行数据统计实战,生成丰富的图表报告(附源码)

实现功能 1.对禅道上的bug进行定制化统计,生成丰富的图表报告 2.通过jenkins自动构建,每日邮件通知结果 准备工作 配置很简单,一次配置,长期受用。 1.禅道上bug严重程度定义(后台->自定义...

python达人 ⋅ 05/25 ⋅ 0

16道Python经典面试题及答案

1.Python是如何进行内存管理的? 答:从三个方面来说,一对象的引用计数机制,二垃圾回收机制,三内存池机制 一、对象的引用计数机制 Python内部使用引用计数,来保持追踪内存中的对象,所有对象...

阿豪boy ⋅ 05/17 ⋅ 0

Python 数据挖掘学习 一 结巴分词

近期,想对古典小说进行索引,和知识挖掘,所以研究了下python数据挖掘方面的知识 Python安装 python学习 一 python语法,及变量类型 python学习 二 爬一个图片网站上 python学习 二 02 爬一...

shuilan0066 ⋅ 01/22 ⋅ 0

Python处理正则表达式超时的办法

title: Python处理正则表达式超时的办法 tags: [python3, 正则表达式超时, re模块] date: 2018-04-27 21:40:21 categories: Python keywords: python3, 正则表达式, re模块, linux信号 最近在...

PigPeek ⋅ 04/27 ⋅ 0

Python Fire试用体验

之前用Python写过一些CLI的小工具,在CLI命令行传参处理上,一般都是用argparse,最近看到Google开源的Python Fire(2017-3-2就开源了), 把argparse包装了,可以自动将代码转变成 CLI,开发...

ahlfors ⋅ 05/24 ⋅ 0

初学者学习python2还是python3?

如果你是一个初学者,或者你以前接触过其他的编程语言,你可能不知道,在开始学习python的时候都会遇到一个比较让人很头疼的问题:版本问题!!是学习python2 还是学习 python3 ?这是非常让...

yunyingoldboy ⋅ 2017/11/09 ⋅ 0

没有更多内容

加载失败,请刷新页面

加载更多

下一页

zblog2.3版本的asp系统是否可以超越卢松松博客的流量[图]

最近访问zblog官网,发现zlbog-asp2.3版本已经进入测试阶段了,虽然正式版还没有发布,想必也不久了。那么作为aps纵横江湖十多年的今天,blog2.2版本应该已经成熟了,为什么还要发布这个2.3...

原创小博客 ⋅ 41分钟前 ⋅ 0

聊聊spring cloud的HystrixCircuitBreakerConfiguration

序 本文主要研究一下spring cloud的HystrixCircuitBreakerConfiguration HystrixCircuitBreakerConfiguration spring-cloud-netflix-core-2.0.0.RELEASE-sources.jar!/org/springframework/......

go4it ⋅ 今天 ⋅ 0

二分查找

二分查找,也称折半查找、二分搜索,是一种在有序数组中查找某一特定元素的搜索算法。搜素过程从数组的中间元素开始,如果中间元素正好是要查找的元素,则搜素过程结束;如果某一特定元素大于...

人觉非常君 ⋅ 今天 ⋅ 0

VS中使用X64汇编

需要注意的是,在X86项目中,可以使用__asm{}来嵌入汇编代码,但是在X64项目中,再也不能使用__asm{}来编写嵌入式汇编程序了,必须使用专门的.asm汇编文件来编写相应的汇编代码,然后在其它地...

simpower ⋅ 今天 ⋅ 0

ThreadPoolExecutor

ThreadPoolExecutor public ThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, ......

4rnold ⋅ 昨天 ⋅ 0

Java正无穷大、负无穷大以及NaN

问题来源:用Java代码写了一个计算公式,包含除法和对数和取反,在页面上出现了-infinity,不知道这是什么问题,网上找答案才明白意思是负的无穷大。 思考:为什么会出现这种情况呢?这是哪里...

young_chen ⋅ 昨天 ⋅ 0

前台对中文编码,后台解码

前台:encodeURI(sbzt) 后台:String param = URLDecoder.decode(sbzt,"UTF-8");

west_coast ⋅ 昨天 ⋅ 0

实验楼—MySQL基础课程-挑战3实验报告

按照文档要求创建数据库 sudo sercice mysql startwget http://labfile.oss.aliyuncs.com/courses/9/createdb2.sqlvim /home/shiyanlou/createdb2.sql#查看下数据库代码 代码创建了grade......

zhangjin7 ⋅ 昨天 ⋅ 0

一起读书《深入浅出nodejs》-node模块机制

node 模块机制 前言 说到node,就不免得提到JavaScript。JavaScript自诞生以来,经历了工具类库、组件库、前端框架、前端应用的变迁。通过无数开发人员的努力,JavaScript不断被类聚和抽象,...

小草先森 ⋅ 昨天 ⋅ 0

Java桌球小游戏

其实算不上一个游戏,就是两张图片,不停的重画,改变ball图片的位置。一个左右直线碰撞的,一个有角度碰撞的。 左右直线碰撞 package com.bjsxt.test;import javax.swing.*;import j...

森林之下 ⋅ 昨天 ⋅ 0

没有更多内容

加载失败,请刷新页面

加载更多

下一页

返回顶部
顶部