- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当我尝试使用ElasticSearch查询一个索引而不查询另一个索引时,我不断收到此错误:
elasticsearch.exceptions.RequestError: RequestError(400, 'search_phase_execution_exception', 'failed to
create query: {\n "multi_match" : {\n "query" : "bob",\n "fields" : [\n
"additional_comments^1.0",\n "age^1.0",\n "first_name^1.0",\n "gender^1.0",\n
"needs^1.0",\n "program_number^1.0",\n "read^1.0",\n "sheet_size^1.0",\n
"shoe_size_category^1.0",\n "shoe_sock_size^1.0",\n "shoe_type^1.0",\n
"time_chosen^1.0",\n "wants^1.0",\n "wear^1.0"\n ],\n "type" : "best_fields",\n
"operator" : "OR",\n "slop" : 0,\n "fuzziness" : "50",\n "prefix_length" : 0,\n
"max_expansions" : 50,\n "zero_terms_query" : "NONE",\n "auto_generate_synonyms_phrase_query" :
true,\n "fuzzy_transpositions" : true,\n "boost" : 1.0\n }\n}')
def query_object(index, fields, query, page, per_page, fuzziness=0):
print(index)
print(query)
print(fields)
search = current_app.elasticsearch.search(
index=index,
body={'query': {'multi_match': {'query': query, 'fields': fields, 'fuzziness': fuzziness}},
'from': (page - 1) * per_page, 'size': per_page}
)
ids = [int(hit['_id']) for hit in search['hits']['hits']]
return ids, search['hits']['total']['value']
class SearchableMixin(object):
@classmethod
def search_object(cls, fields, expression, page, per_page, fuzziness=0):
ids, total = query_object(
cls.__tablename__, fields, expression, page, per_page, fuzziness=fuzziness)
if total == 0:
return cls.query.filter_by(id=0), 0
when = []
for i in range(len(ids)):
when.append((ids[i], i))
return cls.query.filter(cls.id.in_(ids)).order_by(
db.case(when, value=cls.id)), total
class User(db.Model, UserMixin, SearchableMixin):
__searchable__ = ['email', 'phone', 'street_address',
'city', 'state', 'zip_code', 'last_reminded']
id = db.Column(db.Integer, primary_key=True)
email = db.Column(db.String(100), unique=True)
phone = db.Column(db.String(20), nullable=True, default=None)
password = db.Column(db.String(200))
street_address = db.Column(db.String(100))
city = db.Column(db.String(100))
state = db.Column(db.String(52))
zip_code = db.Column(db.String(10))
last_reminded = db.Column(db.String(40), default=datetime.utcnow().strftime(
"%A, %B %e{}, %Y".format(suffix(datetime.today().day))))
admin = db.Column(db.Boolean, default=False)
wish_lists = db.relationship('WishList', backref='sponsor', lazy='dynamic')
drives = db.relationship(
'HolidayCheerDrive', secondary=years, lazy='dynamic')
class WishList(db.Model, SearchableMixin):
__searchable__ = ['program_number', 'first_name', 'age', 'gender', 'wants', 'needs', 'wear',
'read', 'shoe_sock_size', 'shoe_size_category', 'shoe_type', 'sheet_size', 'additional_comments', 'time_chosen',
]
id = db.Column(db.Integer, primary_key=True)
program_number = db.Column(db.String(4))
first_name = db.Column(db.String(20))
age = db.Column(db.String(10))
gender = db.Column(db.String(20))
wants = db.Column(db.String(300))
needs = db.Column(db.String(300))
wear = db.Column(db.String(300))
read = db.Column(db.String(300))
pant_dress_size = db.Column(db.String(20), default='unspecified')
shirt_blouse_size = db.Column(db.String(20), default='unspecified')
jacket_sweater_size = db.Column(db.String(20), default='unspecified')
shoe_sock_size = db.Column(db.String(20), default='unspecified')
shoe_size_category = db.Column(db.String(20), default='unspecified')
shoe_type = db.Column(db.String(50), nullable=True, default=None)
sheet_size = db.Column(db.String(20))
additional_comments = db.Column(db.Text(), nullable=True, default=None)
time_chosen = db.Column(db.String(40), nullable=True, default=None)
sponsor_id = db.Column(db.Integer, db.ForeignKey(
'user.id'), nullable=True, default=None)
drive_id = db.Column(db.Integer, db.ForeignKey(
'holiday_cheer_drive.id'), nullable=False, default=None)
time_chosen
可搜索的术语,因为它尚未定义,但这没有帮助。我也尝试仅搜索单个字段,但也没有用。当我搜索用户时,它不会返回任何错误。据我所知,python路由似乎没有任何错误,它们是:
@bp.route('/manage_users', methods=['GET', 'POST'])
#@admin_only
def manage_users():
form = SearchUsersForm()
page = request.args.get('page', 1, type=int)
if not form.validate():
all_users = User.query.all()
total = len(all_users)
start = ((page-1) * current_app.config['RESULTS_PER_PAGE'])
end = (start + current_app.config['RESULTS_PER_PAGE'])
if end >= total:
display_users = all_users[start:]
else:
display_users = all_users[start:end]
else:
if form.fields.data == 'default':
fields = [field for field in User.__searchable__]
elif form.fields.data == 'address':
fields = ['street_address', 'city', 'state', 'zip_code']
else:
fields = [form.fields.data]
fuzzy = True
if fuzzy:
fuzziness = 50
else:
fuzziness = 0
display_users, total = User.search_object(fields, form.q.data, page,
current_app.config['RESULTS_PER_PAGE'], fuzziness=fuzziness)
q = form.q.data if form.q.data else None
next_url = url_for('admin.manage_users', q=q, page=page + 1) \
if total > page * current_app.config['RESULTS_PER_PAGE'] else None
prev_url = url_for('admin.manage_users', q=q, page=page - 1) \
if page > 1 else None
context = {
'next_url': next_url,
'prev_url': prev_url,
'display_users': display_users,
'form': form,
}
return render_template('/admin/manage_users.html', **context)
@bp.route('/manage_wish_lists', methods=['GET', 'POST'])
#@admin_only
def manage_wish_lists():
form = SearchWishListsForm()
page = request.args.get('page', 1, type=int)
if not form.validate():
all_wish_lists = WishList.query.all()
total = len(all_wish_lists)
start = ((page-1) * current_app.config['RESULTS_PER_PAGE'])
end = (start + current_app.config['RESULTS_PER_PAGE'])
if end >= total:
display_lists = all_wish_lists[start:]
else:
display_lists = all_wish_lists[start:end]
else:
if form.fields.data == 'default':
fields = [field for field in WishList.__searchable__]
elif form.fields.data == 'wish_list_items':
fields = ['wants', 'need', 'wear', 'read']
elif form.fields.data == "shoes":
fields = ['shoe_sock_size', 'shoe_size_category', 'shoe_type']
else:
fields = [form.fields.data]
fuzzy = True
if fuzzy:
fuzziness = 50
else:
fuzziness = 0
display_lists, total = WishList.search_object(fields, form.q.data, page,
current_app.config['RESULTS_PER_PAGE'], fuzziness=fuzziness)
q = form.q.data if form.q.data else None
next_url = url_for('admin.manage_wish_lists', q=q, page=page + 1) \
if total > page * current_app.config['RESULTS_PER_PAGE'] else None
prev_url = url_for('admin.manage_wish_lists', q=q, page=page - 1) \
if page > 1 else None
context = {
'next_url': next_url,
'prev_url': prev_url,
'display_lists': display_lists,
'form': form,
}
return render_template('/admin/manage_wish_lists.html', **context)
print(index)
print(query)
print(fields)
import json
body={'query': {'multi_match': {'query': query, 'fields': fields, 'fuzziness': fuzziness}},
'from': (page - 1) * per_page, 'size': per_page}
print(json.dumps(body))
search = current_app.elasticsearch.search(
index=index,
body={'query': {'multi_match': {'query': query, 'fields': fields, 'fuzziness': fuzziness}},
'from': (page - 1) * per_page, 'size': per_page}
)
print(json.dumps(search))
print
语句的编辑输出
#INDEX NAME
user
#QUERY TERMS
bob
#SEARCH FIELDS
['email', 'phone', 'street_address', 'city', 'state', 'zip_code', 'last_reminded']
#BODY OF SEARCH
{"query": {"multi_match": {"query": "bob", "fields": ["email", "phone", "street_address", "city", "state", "zip_code", "last_reminded"], "fuzziness": 50}}, "from": 0, "size": 10}
#SEARCH JSON
{"took": 18, "timed_out": false, "_shards": {"total": 1, "successful": 1, "skipped": 0, "failed": 0}, "hits": {"total": {"value": 0, "relation": "eq"}, "max_score": null, "hits": []}}
#INDEX NAME
wish_list
#QUERY TERMS
bob
#SEARCH FIELDS
['program_number', 'first_name', 'age', 'gender', 'wants', 'needs', 'wear', 'read', 'shoe_sock_size', 'shoe_size_category', 'shoe_type', 'sheet_size', 'additional_comments', 'time_chosen']
#BODY OF SEARCH
{"query": {"multi_match": {"query": "bob", "fields": ["program_number", "first_name", "age", "gender", "wants", "needs", "wear", "read", "shoe_sock_size", "shoe_size_category", "shoe_type", "sheet_size", "additional_comments", "time_chosen"], "fuzziness": 50}}, "from": 0, "size": 10}
#Cannot build query so search object never instantiates
additional_comments
是文本列而不是字符串列;这有可能发挥作用吗?
at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) ~[elasticsearch-7.6.1.jar:7.6.1]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[?:?]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[?:?]
at java.lang.Thread.run(Thread.java:830) ~[?:?]
[2020-03-23T09:34:43,437][DEBUG][o.e.a.s.TransportSearchAction] [LAPTOP-G8TTIC4C] All shards failed for phase: [query]
org.elasticsearch.index.query.QueryShardException: failed to create query: {
"multi_match" : {
"query" : "bob",
"fields" : [
"additional_comments^1.0",
"age^1.0",
"first_name^1.0",
"gender^1.0",
"needs^1.0",
"program_number^1.0",
"read^1.0",
"sheet_size^1.0",
"shoe_size_category^1.0",
"shoe_sock_size^1.0",
"shoe_type^1.0",
"time_chosen^1.0",
"wants^1.0",
"wear^1.0"
],
"type" : "best_fields",
"operator" : "OR",
"slop" : 0,
"fuzziness" : "50",
"prefix_length" : 0,
"max_expansions" : 50,
"zero_terms_query" : "NONE",
"auto_generate_synonyms_phrase_query" : true,
"fuzzy_transpositions" : true,
"boost" : 1.0
}
}
at org.elasticsearch.index.query.QueryShardContext.toQuery(QueryShardContext.java:350) ~[elasticsearch-7.6.1.jar:7.6.1]
at org.elasticsearch.index.query.QueryShardContext.toQuery(QueryShardContext.java:333) ~[elasticsearch-7.6.1.jar:7.6.1]
at org.elasticsearch.search.SearchService.parseSource(SearchService.java:750) ~[elasticsearch-7.6.1.jar:7.6.1]
at org.elasticsearch.search.SearchService.createContext(SearchService.java:591) ~[elasticsearch-7.6.1.jar:7.6.1]
at org.elasticsearch.search.SearchService.createAndPutContext(SearchService.java:550) ~[elasticsearch-7.6.1.jar:7.6.1]
at org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:351) ~[elasticsearch-7.6.1.jar:7.6.1]
at org.elasticsearch.search.SearchService.lambda$executeQueryPhase$1(SearchService.java:343) ~[elasticsearch-7.6.1.jar:7.6.1]
at org.elasticsearch.action.ActionListener.lambda$map$2(ActionListener.java:146) ~[elasticsearch-7.6.1.jar:7.6.1]
at org.elasticsearch.action.ActionListener$1.onResponse(ActionListener.java:63) [elasticsearch-7.6.1.jar:7.6.1]
at org.elasticsearch.action.ActionRunnable.lambda$supply$0(ActionRunnable.java:58) [elasticsearch-7.6.1.jar:7.6.1]
at org.elasticsearch.action.ActionRunnable$2.doRun(ActionRunnable.java:73) [elasticsearch-7.6.1.jar:7.6.1]
at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) [elasticsearch-7.6.1.jar:7.6.1]
at org.elasticsearch.common.util.concurrent.TimedRunnable.doRun(TimedRunnable.java:44) [elasticsearch-7.6.1.jar:7.6.1]
at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:692) [elasticsearch-7.6.1.jar:7.6.1]
at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) [elasticsearch-7.6.1.jar:7.6.1]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]
at java.lang.Thread.run(Thread.java:830) [?:?]
Caused by: java.lang.IllegalArgumentException: Can only use fuzzy queries on keyword and text fields - not on [shoe_sock_size] which is of type [long]
at org.elasticsearch.index.mapper.MappedFieldType.fuzzyQuery(MappedFieldType.java:356) ~[elasticsearch-7.6.1.jar:7.6.1]
at org.elasticsearch.index.search.MatchQuery$MatchQueryBuilder.lambda$newTermQuery$0(MatchQuery.java:569) ~[elasticsearch-7.6.1.jar:7.6.1]
at org.elasticsearch.index.search.MatchQuery$MatchQueryBuilder.newTermQuery(MatchQuery.java:579) ~[elasticsearch-7.6.1.jar:7.6.1]
at org.elasticsearch.index.search.MatchQuery.parse(MatchQuery.java:277) ~[elasticsearch-7.6.1.jar:7.6.1]
at org.elasticsearch.index.search.MultiMatchQuery.buildFieldQueries(MultiMatchQuery.java:108) ~[elasticsearch-7.6.1.jar:7.6.1]
at org.elasticsearch.index.search.MultiMatchQuery.parse(MultiMatchQuery.java:76) ~[elasticsearch-7.6.1.jar:7.6.1]
at org.elasticsearch.index.query.MultiMatchQueryBuilder.doToQuery(MultiMatchQueryBuilder.java:833) ~[elasticsearch-7.6.1.jar:7.6.1]
at org.elasticsearch.index.query.AbstractQueryBuilder.toQuery(AbstractQueryBuilder.java:99) ~[elasticsearch-7.6.1.jar:7.6.1]
at org.elasticsearch.index.query.QueryShardContext.lambda$toQuery$1(QueryShardContext.java:334) ~[elasticsearch-7.6.1.jar:7.6.1]
at org.elasticsearch.index.query.QueryShardContext.toQuery(QueryShardContext.java:346) ~[elasticsearch-7.6.1.jar:7.6.1]
... 17 more
最佳答案
我发现,当我将搜索字段的数据类型显式设置为“文本”时,在所有不搜索类似数字的字段的情况下,查询都可以正常构建。以前,所有字段都无法正确构建。
我已将SearchableMixin
类中的索引类函数设置为以下内容:
def add_to_index(index, model):
payload = {}
properties = {}
for field in model.__searchable__:
payload[field] = getattr(model, field)
properties[field] = {'type': 'text'}
payload['mappings'] = {'properties': properties}
current_app.elasticsearch.index(index=index, id=model.id, body=payload)
program_number
,
shoe_sock_size
和
age
都是整数或强制转换为字符串的浮点数)。我将研究或询问另一个问题来解决该问题。
关于python - Flask应用程序中的ElasticSearch RequestError:查询仅适用于两个模型之一(search_phase_execution_exception,创建查询失败),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60805908/
可不可以命名为MVVM模型?因为View通过查看模型数据。 View 是否应该只与 ViewModelData 交互?我确实在某处读到正确的 MVVM 模型应该在 ViewModel 而不是 Mode
我正在阅读有关设计模式的文章,虽然作者们都认为观察者模式很酷,但在设计方面,每个人都在谈论 MVC。 我有点困惑,MVC 图不是循环的,代码流具有闭合拓扑不是很自然吗?为什么没有人谈论这种模式: mo
我正在开发一个 Sticky Notes 项目并在 WPF 中做 UI,显然将 MVVM 作为我的架构设计选择。我正在重新考虑我的模型、 View 和 View 模型应该是什么。 我有一个名为 Not
不要混淆:How can I convert List to Hashtable in C#? 我有一个模型列表,我想将它们组织成一个哈希表,以枚举作为键,模型列表(具有枚举的值)作为值。 publi
我只是花了一些时间阅读这些术语(我不经常使用它们,因为我们没有任何 MVC 应用程序,我通常只说“模型”),但我觉得根据上下文,这些意味着不同的东西: 实体 这很简单,它是数据库中的一行: 2) In
我想知道你们中是否有人知道一些很好的教程来解释大型应用程序的 MVVM。我发现关于 MVVM 的每个教程都只是基础知识解释(如何实现模型、 View 模型和 View ),但我对在应用程序页面之间传递
我想realm.delete() 我的 Realm 中除了一个模型之外的所有模型。有什么办法可以不列出所有这些吗? 也许是一种遍历 Realm 中当前存在的所有类型的方法? 最佳答案 您可以从您的 R
我正在尝试使用 alias 指令模拟一个 Eloquent 模型,如下所示: $transporter = \Mockery::mock('alias:' . Transporter::class)
我正在使用 stargazer 创建我的 plm 汇总表。 library(plm) library(pglm) data("Unions", package = "pglm") anb1 <- pl
我读了几篇与 ASP.NET 分层架构相关的文章和问题,但是读得太多后我有点困惑。 UI 层是在 ASP.NET MVC 中开发的,对于数据访问,我在项目中使用 EF。 我想通过一个例子来描述我的问题
我收到此消息错误: Inceptionv3.mlmodel: unable to read document 我下载了最新版本的 xcode。 9.4 版测试版 (9Q1004a) 最佳答案 您没有
(同样,一个 MVC 验证问题。我知道,我知道......) 我想使用 AutoMapper ( http://automapper.codeplex.com/ ) 来验证我的创建 View 中不在我
需要澄清一件事,现在我正在处理一个流程,其中我有两个 View 模型,一个依赖于另一个 View 模型,为了处理这件事,我尝试在我的基本 Activity 中注入(inject)两个 View 模型,
如果 WPF MVVM 应该没有代码,为什么在使用 ICommand 时,是否需要在 Window.xaml.cs 代码中实例化 DataContext 属性?我已经并排观看并关注了 YouTube
当我第一次听说 ASP.NET MVC 时,我认为这意味着应用程序由三个部分组成:模型、 View 和 Controller 。 然后我读到 NerdDinner并学习了存储库和 View 模型的方法
Platform : ubuntu 16.04 Python version: 3.5.2 mmdnn version : 0.2.5 Source framework with version :
我正在学习本教程:https://www.raywenderlich.com/160728/object-oriented-programming-swift ...并尝试对代码进行一些个人调整,看看
我正试图围绕 AngularJS。我很喜欢它,但一个核心概念似乎在逃避我——模型在哪里? 例如,如果我有一个显示多个交易列表的应用程序。一个列表向服务器查询匹配某些条件的分页事务集,另一个列表使用不同
我在为某个应用程序找出最佳方法时遇到了麻烦。我不太习惯取代旧 TLA(三层架构)的新架构,所以这就是我的来源。 在为我的应用程序(POCO 类,对吧??)设计模型和 DAL 时,我有以下疑问: 我的模
我有两个模型:Person 和 Department。每个人可以在一个部门工作。部门可以由多人管理。我不确定如何在 Django 模型中构建这种关系。 这是我不成功的尝试之一 [models.py]:
我是一名优秀的程序员,十分优秀!