2016-10-28 8 views
0

현재 탄성 검색을 사용하고 있으며 여러 유형의 쿼리가 있습니다. 그 중 match_phrase 쿼리를 사용합니다. 이것을 사용하는 색인은 문자 메시지 용 영어 분석기를 사용합니다. 구문을 검색 할 때 정확한 결과가 기대되지만 검색 용어에 영어 단어 (예 : remove)가 있으면 "제거됨", "제거 중", "제거됨"과 같은 단어가 표시됩니다.영어 분석기를 사용하여 ElasticSearch에서 구문 검색

내 구문 검색과 어떻게 일치합니까? 이 같은 쿼리에 대해 match_phrase 이외의 더 좋은 옵션이 있습니까?

분석기를 교체하지 않고도 가능합니까? 아래는 (은 다른 일을 할 수 있도록 구조화) 내 쿼리입니다 :

[MappingTypes.MESSAGE]: { 
    properties: { 
     text: { 
     type: 'string', 
     index: 'analyzed', 
     analyzer: 'english', 
     term_vector: 'with_positions_offsets' 
     }, 
     ownerId: { 
     type: 'string', 
     index: 'not_analyzed', 
     store: true 
     }, 
     groupId: { 
     type: 'string', 
     index: 'not_analyzed', 
     store: true 
     }, 
     itemId: { 
     type: 'string', 
     index: 'not_analyzed', 
     store: true 
     }, 
     createdAt: { 
     type: 'date' 
     }, 
     editedAt: { 
     type: 'date' 
     }, 
     type: { 
     type: 'string', 
     index: 'not_analyzed' 
     } 
    } 
    } 
+0

왜 그런 경우 영어 분석기를 삭제할 수 없습니까? – ChintanShah25

+0

쿼리에서 단독으로 사용중인 분석기를 제어 할 수 있습니까? 필자는 '분석기'를 키워드로 설정하는 등의 작업을 시도하지만 실패합니다. 또 다른 메모에서는 ES 1.5도 사용하고 있습니다. –

+0

나는 키워드를 사용할 수 있었지만, 실제로 작동하려면 키워드로 색인을 생성해야합니까? 그대로, 아무 결과도 얻지 못합니다. –

답변

1

당신은 다른 방법으로 필드를 사용하는 multi-fields을 사용할 수 있습니다 (하나의 정확한 일치 : 여기

query: { 
    fields : ['_id', 'ownerId'], 
    from: 0, 
    size: 20, 
    query: { 
     filtered: { 
      filter: { 
       and: [group ids] 
      }, 
      query: { 
       bool: { 
        must: { 
         match_phrase: { 
           text: "remove" 
         } 
        } 
        } 
      } 
     } 
    } 
} 

그리고 나의 인덱스 하나는 부분 일치 등).

기본 분석기 인 standard analyzer으로 형태소 분석을 제거 할 수 있습니다. 당신은 당신이 text

으로 되돌릴 수 매핑에게 당신이 text.standard를 사용해야하고 형태소 분석을 수행하고자 할 때 (제거 제거합니다 일치 할) 일치를 원할 때마다 그 후

POST test_index 
{ 
    "mappings": { 
    "test_type": { 
     "properties": { 
     "text": { 
      "type": "string", 
      "index": "analyzed", 
      "analyzer": "english", 
      "term_vector": "with_positions_offsets", 
      "fields": { 
      "standard": { 
       "type": "string" 
      } 
      } 
     }, 
     "ownerId": { 
      "type": "string", 
      "index": "not_analyzed", 
      "store": true 
     }, 
     "groupId": { 
      "type": "string", 
      "index": "not_analyzed", 
      "store": true 
     }, 
     "itemId": { 
      "type": "string", 
      "index": "not_analyzed", 
      "store": true 
     }, 
     "createdAt": { 
      "type": "date" 
     }, 
     "editedAt": { 
      "type": "date" 
     }, 
     "type": { 
      "type": "string", 
      "index": "not_analyzed" 
     } 
     } 
    } 
    } 
} 

을 다음과 같이 색인을 만들 수 있습니다 현재 매핑을 업데이트 할 수도 있지만 두 경우 모두 색인 다시을 다시 색인해야합니다.

PUT test_index/_mapping/test_type 
{ 
    "properties": { 
    "text": { 
     "type": "string", 
     "index": "analyzed", 
     "analyzer": "english", 
     "term_vector": "with_positions_offsets", 
     "fields": { 
     "standard": { 
      "type": "string" 
     } 
     } 
    } 
    } 
} 

관련 문제