2013-12-22 7 views
2

elasticsearch에 도메인 이름 색인이 있습니다 (Google에서 연결하고 유지하기 위해 루비와 함께 타이어 보석을 사용하고 있습니다). 그러나 정확한 검색에는 문제가 있습니다.elasticsearch 대시와 정확히 일치

도메인에서 google.com이라는 용어를 검색하면 google.com을 다시 가져 오지만, 역시 --google.com과 같이 대시 (-)가있는 도메인을 반환합니다. research은 - ES에서 와일드 카드이고 내가 할 필요가있는 것은 not_analyzed이지만 실행되지 않습니다.

:domain  => { :type => 'string' , :analyzer => 'whitespace'       }, 
    :domain_2  => { :type => 'string' , :analyzer => 'pattern'       }, 
    :domain_3  => { :type => 'string', :index => 'not_analyzed'       }, 
    :domain_4  => { :type => 'string', :analyzer => 'snowball'       } 

위에서 볼 수있는 것처럼 다른 분석기를 사용해 보았지만 '헤드'플러그인을 사용하여 검색 할 때 모두 동일한 문제가 있습니다.

https://gist.github.com/anonymous/8080839은 내가 테스트 할 데이터 세트를 생성하는 데 사용하는 코드입니다. 내가 찾고있는 것은 Google을 검색하는 기능이며, 원하는 경우 * Google에서 내 자신의 와일드 카드를 구현할 수 있습니까?

내가 삭제하고 내 인덱스하지만 아무리 내가 무엇을 선택 분석기 나 종류를 다시 생성해야 할 거라는 사실을 사임하고있어, 난 여전히 당신은 표시하지 않을 정확히 일치하는

답변

2

를 얻을 수 없다 사용중인 샘플 쿼리 쿼리와 인덱싱이 동일한 텍스트 처리를 사용하고 있습니까?

또한 multi_field - 다양한 방법으로 분석하는 방법을 확인할 수 있습니다.

나는 이것을 설명하는 여러 가지 쿼리로 실행 가능한 예제를 만들었습니다. 도메인이 두 가지 방법으로 색인 된 것을 참고하고, 쿼리를 타격하는 필드주의 : https://www.found.no/play/gist/ecc52fad687e83ddcf73

#!/bin/bash 

export ELASTICSEARCH_ENDPOINT="http://localhost:9200" 

# Create indexes 

curl -XPUT "$ELASTICSEARCH_ENDPOINT/play" -d '{ 
    "mappings": { 
     "type": { 
      "properties": { 
       "domain": { 
        "type": "multi_field", 
        "fields": { 
         "domain": { 
          "type": "string", 
          "analyzer": "standard" 
         }, 
         "whitespace": { 
          "type": "string", 
          "analyzer": "whitespace" 
         } 
        } 
       } 
      } 
     } 
    } 
}' 


# Index documents 
curl -XPOST "$ELASTICSEARCH_ENDPOINT/_bulk?refresh=true" -d ' 
{"index":{"_index":"play","_type":"type"}} 
{"domain":"google.com"} 
{"index":{"_index":"play","_type":"type"}} 
{"domain":"in-google.com"} 
' 

# Do searches 

# Matches both 
curl -XPOST "$ELASTICSEARCH_ENDPOINT/_search?pretty" -d ' 
{ 
    "query": { 
     "match": { 
      "_all": "google.com" 
     } 
    } 
} 
' 

# Also matches "google.com". in-google.com gets tokenized to ["in", "google.com"] 
# and the default match operator is `or`. 
curl -XPOST "$ELASTICSEARCH_ENDPOINT/_search?pretty" -d ' 
{ 
    "query": { 
     "match": { 
      "domain": { 
       "query": "in-google.com" 
      } 
     } 
    } 
} 
' 

# What terms are generated? (Answer: `google.com` and `in`) 
curl -XPOST "$ELASTICSEARCH_ENDPOINT/_search?pretty" -d ' 
{ 
    "size": 0, 
    "facets": { 
     "domain": { 
      "terms": { 
       "field": "domain" 
      } 
     } 
    } 
} 
' 

# This should just match the second document. 
curl -XPOST "$ELASTICSEARCH_ENDPOINT/_search?pretty" -d ' 
{ 
    "query": { 
     "match": { 
      "domain.whitespace": { 
       "query": "in-google.com" 
      } 
     } 
    } 
} 
' 
+0

안녕 알렉스, 덕분에 응답을 위해, 나는 당신의 예제를 이해 좀 확실 해요, 내가했습니다 설치 multi_field 접근 방식 (그 덕분에)에서 제안한 것처럼 색인하지만 정확한 도메인을 검색하는 데 여전히 문제가 있습니다. 검색 쿼리가 google인데도 여전히 in-google.com을 표시하는 두 가지 예제 검색어가 있습니다. –

+0

죄송합니다, 코멘트가 내보내기에서 분실 잊어 버렸습니다. 연극을 본다면 그 연극이 포함 된 이유에 대한 의견이 있어야합니다. 마지막 검색어는 --info와 만 일치합니다. 더 명확한 설명을 포함하도록 답변을 업데이트했습니다. 이것이 도움이 되었으면 좋겠다. –

+0

나는 이것 (그리고 Play)을 조금 더 이해하기 시작했다. https://www.found.no/play/gist/dd354aad8703837877cf 이것은 조금 더 많은 데이터를 가지고 진행중인 나의 현재 작업이다. 당신은 잘 작동하는 정확한 일치를 볼 수 있습니다. 그러나 지금는 와일드 카드 검색입니다. google *을 검색하고 싶다면 google이 megoogle과 같이 나타납니다. –

관련 문제