2014-07-22 4 views
0

현재 나는 elasticsearch로 작업 중이며 클러스터의 문서를 "검색"하려고합니다. 이것은 내가 예상 한 결과를 얻지 못하는 곳입니다. 나는 그들이 모두 검색어 키워드 "te"와 일치해야하므로 4 개의 결과가 반환되기를 바랬습니다. GET _searchElasticSearch가 올바른 결과를 반환하지 않습니다.

{ 
"query": { 
    "filtered" : { 
     "filter" : { 
      "term" : { 
       "source_id" : 1 
      } 
     }, 
     "query": { 
      "bool" : { 
       "must" : { 
        "term" : { "_all" : "te" } 
       } 
      } 
     } 
    } 
}, 
"sort": [ 
    { 
    "date": { 
     "order": "desc" 
    } 
    } 
], 
    "from": 0, 
    "size": 5 
} 

이 쿼리를 실행할 때 나는 (내가 4를 기대하면서) 단지 2 개의 결과만을 얻습니다. 다음 "대상"필드와 나는 4 개 결과를 얻을 부분 : 나는 "{} 쿼리를"제거하면 쿼리 당

{ 
"subject": ["Testbericht"] 
"subject": ["test"] 
"subject": ["Testbericht"] 
"subject": ["Test to myself"] 
} 

는 쿼리의 필터는 특정 소스에서 결과를 반환하는 것입니다 (1 소스를).

내 매핑 :

{ 
    "messages": { 
     "mappings": { 
     "message": { 
      "_id": { 
       "index": "not_analyzed" 
      }, 
      "properties": { 
       "addresses": { 
        "type": "nested", 
        "properties": { 
        "displayname": { 
         "type": "string" 
        }, 
        "email": { 
         "type": "string" 
        }, 
        "name": { 
         "type": "string" 
        }, 
        "type": { 
         "type": "string" 
        } 
        } 
       }, 
       "body": { 
        "type": "string" 
       }, 
       "date": { 
        "type": "date", 
        "format": "dateOptionalTime" 
       }, 
       "files": { 
        "type": "nested", 
        "properties": { 
        "size": { 
         "type": "long" 
        }, 
        "title": { 
         "type": "string" 
        }, 
        "type": { 
         "type": "string" 
        } 
        } 
       }, 
       "folders": { 
        "type": "nested", 
        "properties": { 
        "id": { 
         "type": "integer" 
        } 
        } 
       }, 
       "size": { 
        "type": "long" 
       }, 
       "source_id": { 
        "type": "integer" 
       }, 
       "subject": { 
        "type": "string" 
       } 
      } 
     } 
     } 
    } 
} 

내가 _all = 검색하려고 할 때 얻을 결과 "테"

{ 
"subject": ["test"] 
"subject": ["Testbericht"] 
} 

삽입 문서 :

// PHP client from https://github.com/elasticsearch/elasticsearch-php 
// $this->search = new Elasticsearch\Client(); 
// $id is an unique string 
// $attributes is an array of the attributes 
public function insert($id, array $attributes) 
{ 
    $params = [ 
     'index' => self::INDEX, 
     'type' => self::TYPE, 
     'id' => $id, 
     'body' => [ 
      'source_id' => $attributes['source_id'], 
      'date' => $attributes['date']->format(DateTime::ISO8601), 
      'size' => $attributes['size'], 
      'subject' => $attributes['subject'], 
      'body' => $attributes['body'], 
      'addresses' => $attributes['addresses'], 
      'files' => $attributes['files'], 
      'folders' => $attributes['folders'], 
     ], 
    ]; 

    try 
    { 
     $this->search->index($params); 

     return true; 
    } 
    catch(Exception $e) 
    { 
     throw new Exception($e->getMessage()); 
    } 

    return false; 
} 
+0

u 쿼리를 실행할 때 얻을 수있는 두 가지 결과는 무엇입니까? 또한 인덱싱하는 동안 분석기가 사용한 것은 무엇입니까? – keety

+0

귀하는 귀하의 질의를 게시했습니다. 매핑도 게시하십시오. 더 많은 정보가 없다면 나는 그것이 현재 case-sensetive로 매핑되어 있다고 생각할 것입니다. – Brandon

+0

나는 특정 분석기를 사용하지 않고 있습니까? – Floris

답변

0

그것은 당신을 보인다 모든 문자열 필드에서 표준 분석기를 사용하고 있습니다. 이 분석기는 소문자를 사용하지만 공백과 일부 특수 문자는 토큰 화하지 않습니다. 당신은 부분적으로 일치하는 "te"를 찾고 있습니다. 또한 Test 및 TestBericht의 용어가 아니어야합니다. 나는 당신이 제공하는 매핑이 정확하지 않다고 생각한다. 그렇지 않으면 "te sterk"에 대한 설명처럼 "te"라는 용어를 포함하는 다른 필드가 있거나 뭔가를 간과하고있다. 또한 문서를 추가 할 때 사용한 명령과 완전한 응답을 제공 할 수 있습니까?

+0

PHP 클라이언트 (기본 인덱스 메소드)를 사용하고 있습니다. 내 (간단한) PHP 함수를 내 게시물에 추가했습니다. 내가 원하는대로 키워드를 어떻게 매치시킬 수 있을지 생각해보십시오. – Floris

+0

ngram 또는 prefix-ngram 분석기를 인덱스 분석기 및 검색 분석기와 함께 살펴보십시오. –

+0

불행하게도 와일드 카드 ("와일드 카드": { "_ all": "* te *"}) 옵션을 사용하면 올바른 결과를 얻습니다. 이것이 올바른 방법일까요, 아니면 매우 자원이 비쌉니까? – Floris

관련 문제