2015-02-04 6 views
1

나는 탄성 검색에 이상한 행동을하고 있습니다. 공백, +, -의 경우 단어를 스펠링하는 맞춤형 토크 나이저와 함께 맞춤 분석기를 사용하고 있습니다.elasticsearch phrase_prefix 예상 결과

내가

{ 
    "query": { 
    "match_phrase_prefix": { 
     "name.default": { 
     "query": "paris oly" 
     } 
    } 
    } 
} 

을 찾고 있어요 내가 같은 결과를 얻을 수 나는 전혀 결과를 얻을 올림피아 등 ... 하지만

{ 
    "query": { 
    "match_phrase_prefix": { 
     "name.default": { 
     "query": "paris ol" 
     } 
    } 
    } 
} 

을 찾고 있어요 예상 파리.

설정 :

 "analysis": { 
      "analyzer": { 
       "customAnalyzer": { 
       "type": "custom", 
       "filter": "lowercase", 
       "tokenizer": "customTokenizer" 
       }, 
      "tokenizer": { 
       "customTokenizer": { 
       "pattern": "[\\+\\s-]", 
       "type": "pattern" 
       } 
      } 
     } 

필드 매핑 다음 문서의 일부

{ 
    "name": { 
       "properties": { 
         "default": { 
         "type": "string", 
         "analyzer": "customAnalyzer" 
       } 
      } 
     } 
} 

샘플 (요청 필드) :

{ 
"name": { 
       "jp": "パリ オリンピア (劇場)", 
       "default": "Paris Olympia", 
       } 
} 

{  
    "TYPE_NAME": { 
     "dynamic_templates": [ 
     { 
      "name": { 
      "path_match": "*name.*", 
      "match_mapping_type": "string", 
      "mapping": { 
       "type": "string", 
       "analyzer": "customAnalyzer" 
      } 
      } 
     } 
     ], 
     "properties": { 
     "point": { 
      "type": "geo_point" 
     } 
     } 
    } 
} 
+0

분석기 및 몇 가지 샘플 문서를 포함하여 매핑을 게시 할 수 있습니까? –

+0

감사합니다. 게시물을 편집했습니다. – Ofab

답변

1

난 당신이 무엇을 게시 테스트를 시도, 그것은 나를 위해 일했다. 내가 한 일을 게시하고 그 내용을 살펴보고 설정에 대해 다른 점을 파악할 수 있는지 알아보고 추가 질문이 있으면 도와 드리겠습니다. 나를 위해 그런 문서 반환 게시 된 쿼리 중 하나를

DELETE /test_index 

PUT /test_index 
{ 
    "settings": { 
     "number_of_shards": 1, 
     "number_of_replicas": 0, 
     "analysis": { 
     "tokenizer": { 
      "customTokenizer": { 
       "pattern": "[\\+\\s-]", 
       "type": "pattern" 
      } 
     }, 
     "analyzer": { 
      "customAnalyzer": { 
       "type": "custom", 
       "filter": "lowercase", 
       "tokenizer": "customTokenizer" 
      } 
     } 
     } 
    }, 
    "mappings": { 
     "doc": { 
     "properties": { 
      "name": { 
       "properties": { 
        "default": { 
        "type": "string", 
        "analyzer": "customAnalyzer" 
        } 
       } 
      } 
     } 
     } 
    } 
} 

PUT /test_index/doc/1 
{ 
    "name": { 
     "jp": "パリ オリンピア (劇場)", 
     "default": "Paris Olympia" 
    } 
} 

:

내가 매핑 및 분석기를 사용하여 인덱스를 생성/당신이 게시 토크 나이, 당신이 게시 된 문서를 추가

POST /test_index/_search 
{ 
    "query": { 
     "match_phrase_prefix": { 
     "name.default": { 
      "query": "paris oly" 
     } 
     } 
    } 
} 
... 
{ 
    "took": 1, 
    "timed_out": false, 
    "_shards": { 
     "total": 1, 
     "successful": 1, 
     "failed": 0 
    }, 
    "hits": { 
     "total": 1, 
     "max_score": 0.38356602, 
     "hits": [ 
     { 
      "_index": "test_index", 
      "_type": "doc", 
      "_id": "1", 
      "_score": 0.38356602, 
      "_source": { 
       "name": { 
        "jp": "パリ オリンピア (劇場)", 
        "default": "Paris Olympia" 
       } 
      } 
     } 
     ] 
    } 
} 

또는 여기

POST /test_index/_search 
{ 
    "query": { 
     "match_phrase_prefix": { 
     "name.default": { 
      "query": "paris ol " 
     } 
     } 
    } 
} 
... 
{ 
    "took": 1, 
    "timed_out": false, 
    "_shards": { 
     "total": 1, 
     "successful": 1, 
     "failed": 0 
    }, 
    "hits": { 
     "total": 1, 
     "max_score": 0.38356602, 
     "hits": [ 
     { 
      "_index": "test_index", 
      "_type": "doc", 
      "_id": "1", 
      "_score": 0.38356602, 
      "_source": { 
       "name": { 
        "jp": "パリ オリンピア (劇場)", 
        "default": "Paris Olympia" 
       } 
      } 
     } 
     ] 
    } 
} 

편의를 위해 내가 사용하는 코드입니다 :

http://sense.qbox.io/gist/4e58344580dcf01299f7cc2199d0fb7694d2a051

그래서 다른 것이 계속되어야합니다. 내가 시도한 것과 설치가 다른 점을 말할 수 있습니까?

편집 : 그렇지 않으면 오류가 발생하여 토크 나이저와 분석기의 순서를 전환해야했습니다. 그래서 그걸 들여다 볼 수도 있습니다.

+0

다시 한번 감사드립니다! 나는 당신이 말한대로 순서를 바꾸었다. 이제 내 exmple에서 사건이 일하고있다 !!. 하지만 "paris o"를 검색 할 때 여전히 문제가 있습니다. 우리 사이의 차이점은 입니다. 1. 자바 클라이언트를 사용하여 을 삽입했습니다. 내 문서에서 객체를 사용하고 있습니다. 내 설정에서 "dynamic_templates"를 사용하고 있습니다 (기본 게시물에 추가됨) – Ofab