2015-02-03 3 views
3

more like this 쿼리가 작동하는 방식에 대해 생각하고 있으며 뭔가 빠져있는 것 같습니다. 나는이 문서를 읽었지만, ES 문서는 종종 다소 부족하다 ... 부족하다.Elasticsearch이 쿼리와 마찬가지로 more

시도의 목적은 시도 횟수가 here 인 결과를 제한하는 것입니다.

그래서 디버깅을위한 용어 벡터를 포함한 간단한 색인을 설정 한 다음 두 개의 간단한 문서를 추가했습니다. 나는 termvectors 볼 때

DELETE /test_index 

PUT /test_index 
{ 
    "settings": { 
     "number_of_shards": 1, 
     "number_of_replicas": 0 
    }, 
    "mappings": { 
     "doc": { 
     "properties": { 
      "text": { 
       "type": "string", 
       "term_vector": "yes" 
      } 
     } 
     } 
    } 
} 

PUT /test_index/doc/1 
{ 
    "text": "apple, apple, apple, apple, apple" 
} 

PUT /test_index/doc/2 
{ 
    "text": "apple, apple" 
} 

내가 기대 참조 :

POST /test_index/_search 
{ 
    "query": { 
     "more_like_this": { 
     "fields": [ 
      "text" 
     ], 
     "like_text": "apple", 
     "min_term_freq": 1, 
     "percent_terms_to_match": 1, 
     "min_doc_freq": 1 
     } 
    } 
} 
... 
{ 
    "took": 1, 
    "timed_out": false, 
    "_shards": { 
     "total": 1, 
     "successful": 1, 
     "failed": 0 
    }, 
    "hits": { 
     "total": 2, 
     "max_score": 0.5816214, 
     "hits": [ 
     { 
      "_index": "test_index", 
      "_type": "doc", 
      "_id": "1", 
      "_score": 0.5816214, 
      "_source": { 
       "text": "apple, apple, apple, apple, apple" 
      } 
     }, 
     { 
      "_index": "test_index", 
      "_type": "doc", 
      "_id": "2", 
      "_score": 0.5254995, 
      "_source": { 
       "text": "apple, apple" 
      } 
     } 
     ] 
    } 
} 

하지만 경우 : 내가 "min_term_freq": 1로 다음 쿼리를 실행하면

GET /test_index/doc/1/_termvector 
... 
{ 
    "_index": "test_index", 
    "_type": "doc", 
    "_id": "1", 
    "_version": 1, 
    "found": true, 
    "term_vectors": { 
     "text": { 
     "field_statistics": { 
      "sum_doc_freq": 2, 
      "doc_count": 2, 
      "sum_ttf": 7 
     }, 
     "terms": { 
      "apple": { 
       "term_freq": 5 
      } 
     } 
     } 
    } 
} 

GET /test_index/doc/2/_termvector 
{ 
    "_index": "test_index", 
    "_type": "doc", 
    "_id": "2", 
    "_version": 1, 
    "found": true, 
    "term_vectors": { 
     "text": { 
     "field_statistics": { 
      "sum_doc_freq": 2, 
      "doc_count": 2, 
      "sum_ttf": 7 
     }, 
     "terms": { 
      "apple": { 
       "term_freq": 2 
      } 
     } 
     } 
    } 
} 

내가 다시 두 문서를 얻을 "min_term_freq"을 2 (또는 그 이상) 증가 시키면 아무 것도 얻을 수 없지만 두 문서가 모두 반환 될 것으로 기대됩니다.

POST /test_index/_search 
{ 
    "query": { 
     "more_like_this": { 
     "fields": [ 
      "text" 
     ], 
     "like_text": "apple", 
     "min_term_freq": 2, 
     "percent_terms_to_match": 1, 
     "min_doc_freq": 1 
     } 
    } 
} 
... 
{ 
    "took": 1, 
    "timed_out": false, 
    "_shards": { 
     "total": 1, 
     "successful": 1, 
     "failed": 0 
    }, 
    "hits": { 
     "total": 0, 
     "max_score": null, 
     "hits": [] 
    } 
} 

왜? 내가 뭘 놓치고 있니?

"apple"이 5 번 나타나지만 2 번 나타나는 문서는 반환하지 않는 쿼리를 설정하려면 더 좋은 방법이 있습니까? 여기

편의상 코드이다

http://sense.qbox.io/gist/341f9f77a6bd081debdcaa9e367f5a39be9359cc

답변

7

최소 용어 빈도 및 문서 최소 주파수는 실제로 MLT를 수행하기 전에 상기 입력에인가된다. 즉, 입력 텍스트에 apple이 하나만 출현 했으므로 최소 기간 빈도가 2로 설정되어 있기 때문에 사과가 MLT 자격을 얻지 못했습니다. 입력을 "사과 사과"로 변경하면 문제가 해결됩니다.

POST /test_index/_search 
{ 
    "query": { 
     "more_like_this": { 
     "fields": [ 
      "text" 
     ], 
     "like_text": "apple apple", 
     "min_term_freq": 2, 
     "percent_terms_to_match": 1, 
     "min_doc_freq": 1 
     } 
    } 
} 

같은 문서는 분당도 마찬가지입니다. Apple은 atleast 2 문서에 있으므로 min_doc_freq 2까지는 MLT 작업의 입력 텍스트에서 적용됩니다.

+0

감사합니다. Vineeth. 그게 효과가 있는데, 아직도 왜 그런지 이해하지 못합니다. {... "like_text": "apple apple apple", "min_term_freq": 3, ...}을 검색하면 'apple'이 3 번 미만 발생하더라도 두 결과를 모두 얻습니다. 서류. 그렇다면 용어가 최소 빈도 또는 그 이상에서 발생하는 결과로 결과를 어떻게 제한 할 수 있습니까? –

+1

MLT를 사용할 수 있다고 생각하지 않습니다. 최소 주파수 및 최소 문서 주파수 제한은 모두 비교 문서가 아닌 입력 텍스트에 실제로 적용됩니다. 또 다른 방법은 스크립팅 플러그를 사용하여 필터 스크립트 측면에서이를 수행하는 것입니다. - http://stackoverflow.com/questions/28296320/elasticsearch-filter-via-number-of-mentions/28312561#28312561 –

+0

Gotcha. 도와 주셔서 감사합니다. –