2017-12-06 2 views
0

가능 필드가 first_name, middle_initiallast_name 인 경우 이름 검색을 구현하고 있습니다. 일반적으로 검색어는 성을 먼저 사용합니다 (예 : "Smith, A"대신 "Smith, Ashley"를 찾을 때.다른 필드에서 일치하는 항목 위의 검색어와 부분 일치하는 항목의 일치

내 결과가 바람직하지 않게 득점하는 (안젤라와 알렉스는 로버트와 테드 이상이어야합니다) :

  • "스미스, 로저 A"
  • "스미스, 테드 A"
  • "스미스, 안젤라 D "
  • "스미스, 알렉스 N은 "

나는 색인에 모두 많은 것들을 시도했습니다 질의, 그리고 나는 상당한 양의 퍼지 (철자와 음성)를 포함시켜야한다. cross_match 쿼리와 n-gram 분석기를 통한 일부 퍼지 (fuzziness)는이 점을 제외하고는 대부분 나의 필요를 충족 시켰습니다. 편집 : 위의 목록은 _score으로 정렬되므로 다른 것들로 정렬 할 수 없습니다. 온 일치 무엇이든 밖으로 익사하려고

GET /_search 
{ 
    "query": { 
    "bool": { 
     "should": [ 
     { 
      "multi_match": { 
      "query": "smith, a", 
      "type": "cross_fields", 
      "fields": [ 
       "first_name_middle_initial^5", 
       "last_name^10" 
      ] 
      } 
     }, 
     { 
      "multi_match": { 
      "query": "smith, a", 
      "type": "cross_fields", 
      "fields": [ 
       "first_name_middle_initial.phonetic^2", 
       "last_name.phonetic^5" 
      ] 
      } 
     }, 
     { 
      "multi_match": { 
      "query": "smith, a", 
      "type": "cross_fields", 
      "fields": [ 
       "first_name_middle_initial.analyzed^2", 
       "last_name.analyzed^10" 
      ] 
      } 
     }, 
     { 
      "bool": { 
      "should": [ 
       { 
       "match": { 
        "last_name.word_start": { 
        "query": "smith, a", 
        "boost": 10, 
        "operator": "and", 
        "analyzer": "searchkick_word_search" 
        } 
       } 
       }, 
       { 
       "match": { 
        "last_name.word_start": { 
        "query": "smith, a", 
        "boost": 5, 
        "operator": "and", 
        "analyzer": "searchkick_word_search", 
        "fuzziness": 1, 
        "prefix_length": 0, 
        "max_expansions": 3, 
        "fuzzy_transpositions": true 
        } 
       } 
       } 
      ] 
      } 
     }, 
     { 
      "bool": { 
      "should": [ 
       { 
       "match": { 
        "first_name_middle_initial.word_start": { 
        "query": "smith, a", 
        "boost": 10, 
        "operator": "and", 
        "analyzer": "searchkick_word_search" 
        } 
       } 
       } 
      ] 
      } 
     } 
     ] 
    } 
    } 
} 

나는 또한 부스트와 바이올린을했습니다 : 내가 함께 처음 & 중간 이름 색인이 차이를 만들어 있는지 확인하기 위해 노력했다

쿼리 예를 들어, 중간 이니셜, 그리고 심지어 내 이니셜을 포함하지 않거나 내 이니셜을 포함하지 않거나 내가 쿼리에서 참조하고있는 필드 (예 : first_name) 만 포함됩니다. 차별화 된 분야 일 경우 중간 이니셜을 완전히 무시할 수 없습니다.

답변

0

글쎄, 내 문제 중 하나가 오래된 색인 일 수도 있습니다. 그렇지 않은 경우 키는 ngram 분석기를 사용하여 cross_fields과 일치하고 middle_initial이 완전히 독립적으로 간주되는 것으로 나타났습니다 (일종의 tiebreaker). bool 하위 쿼리를 사용하는 것은 의도적이었습니다. 해당 절의 다른 하위 쿼리는 this section of the elasticsearch guide과 같이 cross_fields과 동일한 가중치로 간주되도록하고 싶지 않습니다.

인덱스 매핑 :

{ 
    <snip> 
     "first_name": { 
     "type": "text", 
     "fields": { 
      "phonetic": { 
      "type": "text", 
      "analyzer": "dbl_metaphone" 
      }, 
      "word_start": { 
      "type": "text", 
      "analyzer": "searchkick_word_start_index" // includes "lowercase", "asciifolding", "searchkick_edge_ngram" (ngram from the start of the word) 
      } 
     } 
     }, 
     <snip> 
     "last_name": { 
     "type": "text", 
     "fields": { 
      "phonetic": { 
      "type": "text", 
      "analyzer": "dbl_metaphone" 
      }, 
      "word_start": { 
      "type": "text", 
      "analyzer": "searchkick_word_start_index" 
      } 
     } 
     }, 
     "middle_initial": { 
     "type": "keyword", 
     "fields": { 
      "analyzed": { 
      "type": "text", 
      "analyzer": "searchkick_index" // includes lowercase, asciifolding, shingles, stemmer 
      } 
     }, 
     "ignore_above": 30000 
     }, 
     <snip> 
    } 
    } 
} 

검색어 :

{ 
    "query": { 
    "bool": { 
     "should": [ 
     [ 
      { 
      "multi_match": { 
       "query": "smith, s", 
       "type": "cross_fields", 
       "fields": [ 
       "first_name^2", 
       "last_name^3" 
       ], 
       "tie_breaker": 0.3 
      } 
      }, 
      { 
      "multi_match": { 
       "query": "smith, s", 
       "type": "cross_fields", 
       "fields": [ 
       "first_name.phonetic", 
       "last_name.phonetic" 
       ], 
       "tie_breaker": 0.3 
      } 
      }, 
      { 
      "multi_match": { 
       "query": "smith, s", 
       "type": "cross_fields", 
       "fields": [ 
       "first_name.word_start", 
       "last_name.word_start^2" 
       ], 
       "tie_breaker": 0.3 
      } 
      } 
     ], 
     { 
      "bool": { 
      "should": [ 
      <snip subquery for another field> 
       { 
       "match": { 
        "middle_initial.analyzed": { 
        "query": "s", 
        "operator": "and" 
        } 
       } 
       } 
      ] 
      } 
     } 
     ] 
    } 
    } 
} 
여기에 궁극적으로 내 문제를 해결 무엇

관련 문제