2017-02-19 1 views
0

elasticsearch 2.0에서 5.2로 이동했으며 ngram 검색이 중단되었습니다!Elasticsearch ngram 쿼리가 작동하지 않습니다.

elasticsearch 설정은 제목과 요약 필드에 대한 간단한 ngram 토크 나이저입니다.

settings = { 
    "settings": { 
     "number_of_shards": 1, 
     "number_of_replicas": 0, 
     "analysis": { 
      "filter": { 
       "ngram_filter": { 
        "type": "nGram", 
        "min_gram": 3, 
        "max_gram": 10 
       } 
      }, 
      "analyzer": { 
       "search_ngram_analyzer": { 
        "tokenizer": "standard", 
        "type": "custom", 
        "filter": ["standard", "lowercase", "stop", "asciifolding"] 
       }, 

       "index_ngram_analyzer": { 
        "tokenizer": "standard", 
        "type": "custom", 
        "filter": ["standard", "lowercase", "stop", "asciifolding", "ngram_filter"] 
       } 
      } 
     }, 

    }, 
    "mappings": { 
     "docs": { 
      "properties": { 
       'title': { 
        'boost': 100.0, 
        'search_analyzer': 'search_ngram_analyzer', 
        'analyzer': 'index_ngram_analyzer', 
        'type': 'text', 
       }, 
       'summary': { 
        'boost': 20.0, 
        'search_analyzer': 'search_ngram_analyzer', 
        'analyzer': 'index_ngram_analyzer', 
        'type': 'text', 
       } 
      } 
     } 

    } 
} 

http://localhost:9200/my_index/_search?q=example 반환 그것에 단어 "예"와 문서. 일반적인 쿼리입니다.

그러나 http://localhost:9200/my_index/_search?q=exampl (예 : "e"포함)은 빈 개체를 반환합니다.

설정에 오류가 없습니다. 이것은 API 휴식입니까?

답변

3

이전 버전에서 정상적으로 작동 했습니까?

URI 검색을 사용하고 http://localhost:9200/my_index/_search?q=exampl에서와 같이 필드를 지정하지 않으면 _all 필드가 사용됩니다. 표준 분석기를 사용하기 때문에 ngram이 없습니다.

PUT /my_index 
{ 
    "settings": { 
    "analysis": { 
     "filter": { 
     "ngram_filter": { 
      "type": "nGram", 
      "min_gram": 3, 
      "max_gram": 10 
     } 
     }, 
     "analyzer": { 
     "search_ngram_analyzer": { 
      "tokenizer": "standard", 
      "type": "custom", 
      "filter": [ 
      "standard", 
      "lowercase", 
      "stop", 
      "asciifolding" 
      ] 
     }, 
     "index_ngram_analyzer": { 
      "tokenizer": "standard", 
      "type": "custom", 
      "filter": [ 
      "standard", 
      "lowercase", 
      "stop", 
      "asciifolding", 
      "ngram_filter" 
      ] 
     } 
     } 
    } 
    }, 
    "mappings": { 
    "docs": { 
     "properties": { 
     "title": { 
      "boost": 100, 
      "search_analyzer": "search_ngram_analyzer", 
      "analyzer": "index_ngram_analyzer", 
      "type": "text" 
     }, 
     "summary": { 
      "boost": 20, 
      "search_analyzer": "search_ngram_analyzer", 
      "analyzer": "index_ngram_analyzer", 
      "type": "text" 
     } 
     } 
    } 
    } 
} 


GET /my_index/_analyze 
{ 
    "analyzer": "index_ngram_analyzer", 
    "text": "example exampl" 
} 
GET /my_index/_analyze 
{ 
    "analyzer": "search_ngram_analyzer", 
    "text": "example exampl" 
} 

POST /my_index/docs 
{ 
    "title": "This is an example", 
    "summary": "Some more text" 
} 

GET /my_index/_search?q=example 
GET /my_index/_search?q=exampl 
GET /my_index/_search?q=title:exampl 

DELETE /my_index 
: 사용하려는 쿼리는 재현성을 위해서 /my_index/_search?q=title:exampl

이며, 여기에 콘솔에 대한 전체 예제의 덤프입니다

관련 문제