我有ES版本7的这个ElasticSearch查询:
{
"from": 0,
"simple_query_string": {
"query": "*"
},
"query": {
"bool": {
"must": [
{
"term": {
"organization_id": "fred"
}
},
{
"term": {
"assigned_user_id": "24584080"
}
}
]
}
},
"size": 50,
"sort": {
"updated": "desc"
},
"terminate_after": 50,
}
但是ES给了我这个错误:reason: Unknown key for a START_OBJECT in [simple_query_string]
我的目标是能够对多个字段使用查询字符串,并且还可以将术语/匹配与 bool(boolean) /必须一起使用。我应该放弃查询字符串而只使用
bool.must[{match:"my query"}]
吗?
最佳答案
您可以使用bool以这种方式组合多个查询。 must子句将作为逻辑AND,并确保所有条件都匹配。
您需要在查询部分内包含simple_query_string
添加带有示例文档和搜索查询的工作示例。
索引样本数据
{
"organization_id": 1,
"assigned_user_id": 2,
"title": "welcome"
}{
"organization_id": 2,
"assigned_user_id": 21,
"title": "hello"
}{
"organization_id": 3,
"assigned_user_id": 22,
"title": "hello welocome"
}
搜索查询: {
"query": {
"bool": {
"must": [
{
"simple_query_string": {
"fields" : ["title"],
"query" : "welcome"
}
},
{
"match": {
"organization_id": "1"
}
},
{
"match": {
"assigned_user_id": "2"
}
}
]
}
}
}
搜索结果:"hits": [
{
"_index": "my_index",
"_type": "_doc",
"_id": "1",
"_score": 3.0925694,
"_source": {
"organization_id": 1,
"assigned_user_id": 2,
"title": "welcome"
}
}
]
关于elasticsearch - 如何将simplequerystring与bool/must结合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62686818/