我想在文档中搜索“社交网络营销”。都在一起。但是我继续用分开的词来获得结果。我有以下DSL查询:
{
"fields": ["title"],
"query": {
"bool": {
"should": [{
"match": {
"title": "SEO"
}
}],
"must": [{
"match": {
"content": {
"query": "Marketing in social networks",
"operator": "and"
}
}
}]
}
}
}我没有包含这个短语和标题的文档,但我也得到了结果(文档)与短语的词,以搜索分裂。我要严格搜查。如果没有具有此短语的文档,请不要检索任何文档或只检索带有该标题的文档。为什么操作符和不能工作?
发布于 2016-10-08 14:48:15
你能试着像下面这样使用类型短语吗?见这里它说,
查询首先分析查询字符串以生成一个术语列表。然后,它搜索所有的术语,但只保存包含所有搜索项的文档,这些文档位于相对于彼此的相同位置。
{
"fields": ["title"],
"query": {
"bool": {
"should": [{
"match": {
"title": "SEO"
}
}],
"must": [{
"match": {
"content": {
"query": "Marketing in social networks",
"type": "phrase"
}
}
}]
}
}
}我还没试过呢。
发布于 2017-06-14 12:23:50
第一个答案是好的,但是对于ES,v5使用"type":"phrase"将返回标题中的[WARN ][org.elasticsearch.deprecation.common.ParseField] Deprecated field [type] used, replaced by [match_phrase and match_phrase_prefix query]
所以正确的查询应该包含短语
{
"fields": ["title"],
"query": {
"bool": {
"should": [{
"match": {
"title": "SEO"
}
}],
"must": [{
"match_phrase": {
"content": {
"query": "Marketing in social networks"
}
}
}]
}
}
}https://stackoverflow.com/questions/39931006
复制相似问题