我试图使用简单的查询字符串否定弹性搜索请求中的一些单词和短语。
这就是我所做的:
&q=-"the witcher 3"-game-novel
所以基本上,试图否定一个短语及其后的单词。但这似乎行不通。如果我试图单独否定这些词,它是有效的。如何在一个简单的查询字符串中否定短语和句子?
添加一个包含索引数据、搜索查询和搜索结果的工作示例。
指数数据:
{
"name":"test"
}
{
"name":"game"
}
{
"name":"the witcher"
}
{
"name":"the witcher 3"
}
{
"name":"the"
}
搜索查询:
{
"query": {
"simple_query_string" : {
"query": "-(game | novel) -(the witcher 3)",
"fields": ["name"],
"default_operator": "and"
}
}
}
搜索结果:
"hits": [
{
"_index": "stof_64133051",
"_type": "_doc",
"_id": "4",
"_score": 2.0,
"_source": {
"name": "the"
}
},
{
"_index": "stof_64133051",
"_type": "_doc",
"_id": "3",
"_score": 2.0,
"_source": {
"name": "the witcher"
}
},
{
"_index": "stof_64133051",
"_type": "_doc",
"_id": "1",
"_score": 2.0,
"_source": {
"name": "test"
}
}
]