我们使用 AWS 托管的 Elasticsearch 服务,最近从 1.5 升级到 2.3。我们使用 python 中的 elasticsearch-dsl 包来构建我们的查询并设法迁移了我们的大部分查询,但是无论我尝试什么,geo_distance 都被破坏了。
映射:
{
'company': {
'properties': {
'id': {'type': 'integer'},
'company_number': {'type': 'string'},
'addresses': {
'type': 'nested',
'properties': {
'postcode': {'type': 'string', 'index': 'not_analyzed'},
'location': {'type': 'geo_point'}
}
}
}
}
}
使用 elasticsearch-dsl==0.0.11 的 Python 代码
test_location = '53.5411062377, -2.11485504709'
test_distance = "3miles"
location_filter = F("geo_distance",
location=test_location,
distance=test_distance)
query = query.filter("nested",
path="addresses",
filter=location_filter)
库生成的查询:
{'query': {'filtered': {'filter': {'nested': {'filter': {'geo_distance': {'distance': u'3miles', 'location': '53.5411062377, -2.11485504709'}}, 'path': 'addresses'}}, 'query': {'match_all': {}}}}}
我们在新的 2.3 上创建了一个具有相同映射的全新索引。
更新到 elasticsearch-dsl == 2.1.0 并尝试将过滤器转换为查询后:
geo_query = Q({"bool": {
"must": [
{
"geo_distance": {
"distance": "test_distance",
"addresses__location": test_location,
}
},
]
}})
生成以下查询:
{'query': {'bool': {'must': [{'geo_distance': {'distance': '3 miles', u'addresses.location': {'lat': '53.5411062377', 'lon': '-2.11485504709'}}}]}}}
我们得到以下异常:
RequestError: TransportError(400, u'search_phase_execution_exception', u'failed to find geo_point field [addresses.location]')
我尝试将该字段引用为“location”、“addresses.location”、“addresses”并使用旧的嵌套查询类型。我无法确定映射在 2.3 中是否不再有效,或者我是否构建了错误的查询。
查询
Q({'nested': {'filter': {
'geo_distance': {'distance': u'3miles', 'location': '53.5411062377, -2.11485504709'}
},
'path': 'addresses.location'}})
生成以下错误:
RequestError: TransportError(400, u'search_phase_execution_exception', u'[nested] nested object under path [addresses.location] is not of nested type')
我想我需要添加 lat_lon : True 到映射中,地理距离查询才能工作,但没有一个例子有它。
非常感谢任何帮助,谢谢!
最佳答案
这应该有效:
test_location = '53.5411062377, -2.11485504709'
test_distance = "3miles"
location_query = Q("geo_distance",
addresses__location=test_location,
distance=test_distance)
query = query.filter("nested",
path="addresses",
query=location_query)
关于python - 更新到 elasticsearch 2.3 后无法定位嵌套的地理点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41639772/
关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭4年前。Improvethisquestion我想在固定时间创建一系列低音和高音调的哔哔声。例如:在150毫秒时发出高音调的蜂鸣声在151毫秒时发出低音调的蜂鸣声200毫秒时发出低音调的蜂鸣声250毫秒的高音调蜂鸣声有没有办法在Ruby或Python中做到这一点?我真的不在乎输出编码是什么(.wav、.mp3、.ogg等等),但我确实想创建一个输出文件。
我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-
给定这段代码defcreate@upgrades=User.update_all(["role=?","upgraded"],:id=>params[:upgrade])redirect_toadmin_upgrades_path,:notice=>"Successfullyupgradeduser."end我如何在该操作中实际验证它们是否已保存或未重定向到适当的页面和消息? 最佳答案 在Rails3中,update_all不返回任何有意义的信息,除了已更新的记录数(这可能取决于您的DBMS是否返回该信息)。http://ar.ru
我得到了一个包含嵌套链接的表单。编辑时链接字段为空的问题。这是我的表格:Editingkategori{:action=>'update',:id=>@konkurrancer.id})do|f|%>'Trackingurl',:style=>'width:500;'%>'Editkonkurrence'%>|我的konkurrencer模型:has_one:link我的链接模型:classLink我的konkurrancer编辑操作:defedit@konkurrancer=Konkurrancer.find(params[:id])@konkurrancer.link_attrib
这道题是thisquestion的逆题.给定一个散列,每个键都有一个数组,例如{[:a,:b,:c]=>1,[:a,:b,:d]=>2,[:a,:e]=>3,[:f]=>4,}将其转换为嵌套哈希的最佳方法是什么{:a=>{:b=>{:c=>1,:d=>2},:e=>3,},:f=>4,} 最佳答案 这是一个迭代的解决方案,递归的解决方案留给读者作为练习:defconvert(h={})ret={}h.eachdo|k,v|node=retk[0..-2].each{|x|node[x]||={};node=node[x]}node[
我对最新版本的Rails有疑问。我创建了一个新应用程序(railsnewMyProject),但我没有脚本/生成,只有脚本/rails,当我输入ruby./script/railsgeneratepluginmy_plugin"Couldnotfindgeneratorplugin.".你知道如何生成插件模板吗?没有这个命令可以创建插件吗?PS:我正在使用Rails3.2.1和ruby1.8.7[universal-darwin11.0] 最佳答案 随着Rails3.2.0的发布,插件生成器已经被移除。查看变更日志here.现在
我尝试运行2.x应用程序。我使用rvm并为此应用程序设置其他版本的ruby:$rvmuseree-1.8.7-head我尝试运行服务器,然后出现很多错误:$script/serverNOTE:Gem.source_indexisdeprecated,useSpecification.Itwillberemovedonorafter2011-11-01.Gem.source_indexcalledfrom/Users/serg/rails_projects_terminal/work_proj/spohelp/config/../vendor/rails/railties/lib/r
我正在尝试在我的centos服务器上安装therubyracer,但遇到了麻烦。$geminstalltherubyracerBuildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingtherubyracer:ERROR:Failedtobuildgemnativeextension./usr/local/rvm/rubies/ruby-1.9.3-p125/bin/rubyextconf.rbcheckingformain()in-lpthread...yescheckingforv8.h...no***e
我花了三天的时间用头撞墙,试图弄清楚为什么简单的“rake”不能通过我的规范文件。如果您遇到这种情况:任何文件夹路径中都不要有空格!。严重地。事实上,从现在开始,您命名的任何内容都没有空格。这是我的控制台输出:(在/Users/*****/Desktop/LearningRuby/learn_ruby)$rake/Users/*******/Desktop/LearningRuby/learn_ruby/00_hello/hello_spec.rb:116:in`require':cannotloadsuchfile--hello(LoadError) 最佳
我将应用程序升级到Rails4,一切正常。我可以登录并转到我的编辑页面。也更新了观点。使用标准View时,用户会更新。但是当我添加例如字段:name时,它不会在表单中更新。使用devise3.1.1和gem'protected_attributes'我需要在设备或数据库上运行某种更新命令吗?我也搜索过这个地方,找到了许多不同的解决方案,但没有一个会更新我的用户字段。我没有添加任何自定义字段。 最佳答案 如果您想允许额外的参数,您可以在ApplicationController中使用beforefilter,因为Rails4将参数