2017-02-16 2 views
2

탄성 검색 5.2.0에서이 필터를이 쿼리에 어떻게 추가합니까?Elasticsearch의 function_score 쿼리에 필터를 추가하는 방법 5

필자는 운이없는 필터링 된 배열로 필터를 래핑하려고했습니다.

필터

"filter" : { 
    "term" : { "body.category" : 1} 
} 

쿼리

{ 
    "query": { 
    "function_score": { 
     "query": { 
     "multi_match": { 
      "operator": "and", 
      "query": "my search", 
      "fuzziness": 1, 
      "fields": [ 
      "body.name^5", 
      "body.manufacturer^33", 
      "body.sections.name", 
      "body.sections.parent.name", 
      "body.sections.parent.parent.name" 
      ] 
     } 
     }, 
     "functions": [ 
     { 
      "field_value_factor": { 
      "field": "body.rank" 
      } 
     } 
     ], 
     "score_mode": "multiply" 
    } 
    } 
} 

답변

3

I은 ​​불리언 질의하여 배치하여이를 해결하고있다 필터를 배치했다.

{ 
     "query": { 
     "function_score": { 
      "query": { 
      "bool": { 
       "filter": { 
       "term": { 
        "body.category": 1 
       } 
       }, 
       "should": { 
       "multi_match": { 
        "operator": "and", 
        "query": "my search", 
        "fuzziness": 1, 
        "fields": [ 
        "body.name", 
        "body.manufacturer", 
        "body.sections.name", 
        "body.sections.parent.name", 
        "body.sections.parent.parent.name" 
        ] 
       } 
       } 
      } 
      }, 
      "functions": [ 
      { 
       "field_value_factor": { 
       "field": "body.rank" 
       } 
      } 
      ], 
      "score_mode": "multiply" 
     } 
     } 
    } 
관련 문제