2016-12-01 34 views
0

我想混合搜索整个文档(例如“developer”)和搜索某个字段中的另一个术语(例如“php”) 。 我可以单独做每个搜索,但我不能混合它们。Elastic:在_all上搜索两个术语,其中一个在字段上

这里我举的例子(简化为只显示我的问题):

{ 
    "query": { 
    "function_score": { 
     "query": { 
     "match": { 
      "_all": "developer" 
     }, 
     "multi_match": { 
      "query": "php", 
      "fields": [ 
      "skills.description", 
      "skills.description", 
      "skills.details" 
      ], 
      "operator": "or", 
      "type": "most_fields" 
     } 
     } 
    } 
} 

如果我运行这个例子,我有一个错误:

Parse Failure [Failed to parse source 

有没有办法在两个_all搜索和具有两个术语的特定字段?

谢谢。

回答

1

是,你几乎没有,您需要将它们合并成一个bool/must查询:

{ 
    "query": { 
    "function_score": { 
     "query": { 
     "bool": { 
      "must": [ 
      { 
       "match": { 
       "_all": "developer" 
       } 
      }, 
      { 
       "multi_match": { 
       "query": "php", 
       "fields": [ 
        "skills.description", 
        "skills.description", 
        "skills.details" 
       ], 
       "operator": "or", 
       "type": "most_fields" 
       } 
      } 
      ] 
     } 
     } 
    } 
    } 
} 
+0

哦,只是这个! 非常感谢您指点我。 – Bacteries

+0

真棒很高兴它帮助! – Val

相关问题