2012-07-25 2 views
3

용어를 잘못 설명해 주시면 저를 용서하겠습니다.하지만 ES에 점수를 매기는 데 문제가있어 내 앱에 의미가 있습니다.ElasticSearch가 단일 히트의 tf보다 높은 결과 (idf?)를 초과하는 총 중첩 된 히트 수를 얻으려고합니까?

나는 간단한 몇 가지 분야뿐만 아니라 아이의 가능성이 수백 수천 명의 사용자를 인덱싱하고 각 사용자의 인덱스에 중첩 된 객체 (즉 도서 ->페이지 데이터 모델).

user_id: 1 
    full_name: First User 
    username: firstymcfirsterton 
    posts: 
    id: 2 
    title: Puppies are Awesome 
    tags: 
    - dog house 
    - dog supplies 
    - dogs 
    - doggies 
    - hot dogs 
    - dog lovers 

user_id: 2 
    full_name: Second User 
    username: seconddude 
    posts: 
    id: 3 
    title: Dogs are the best 
    tags: 
    - dog supperiority 
    - dog 
    id: 4 
    title: Why dogs eat? 
    tags: 
    - dog diet 
    - canines 
    id: 5 
    title: Who let the dogs out? 
    tags: 
    - dogs 
    - terrible music 

태그는 "키워드"분석기를 사용하여 입력 "태그", 그리고 10 제목이 증폭되지 밀어 : 인덱스로 전송 점점 JSON은 다음과 같습니다.

"개"를 검색하면 첫 번째 사용자의 점수가 두 번째 사용자의 점수보다 높습니다. 나는 이것이 더 높은 첫 번째 사용자의 tf-idf로해야한다고 가정합니다. 그러나 내 응용 프로그램에서 이상적인 용어에 대한 히트를 가진 사용자가 더 많이 올 것입니다.

게시물 수로 정렬을 시도했지만 사용자가 게시물이 많으면 정크 결과가 나타납니다. 기본적으로 조회수가 많은 게시물을 가진 사용자가 맨 위에 올 수 있도록 고유 한 게시물 조회수를 기준으로 정렬하고 싶습니다.

어떻게해야합니까? 어떤 아이디어?

+1

몇 가지 생각과 질문. 어떻게 검색하고 있는지 게시 할 수 있습니까? 사용하는 쿼리 유형은 큰 차이를 만듭니다. 또한, 나는 "키워드"분석기를 사용하는 것이 좋은 생각이 아니라고 생각합니다. 전체 태그를 단일 용어로 변환합니다. 더 나은 해결책은 표준 분석기 + 사용자 정의 고유 필터 – Zach

+1

@ thoughtpunch를 사용하는 것일 수 있습니다. 또한 100 % 질문을 이해하지 못하지만 적절한 "최상위"문서가 귀하의 예에서'post'가 될 것 같습니다. 그러면이 속성에 'user_id'가 포함됩니다. 나는 수색을 내기하고 전체 체제는 매우 쉬울 것입니다. – karmi

답변

2

우선 @karmi 및 @Zach에 동의합니다. 게시물 일치와 관련된 의미를 파악하는 것이 중요합니다. 간단히하기 위해 일치하는 게시물에 어딘가에 "개"라는 단어가 있다고 가정하고 태그 분석기를 사용하지 않고 태그를 매칭하여 재미있는 정보를 제공합니다.

귀하의 질문을 정확하게 이해하면 관련 게시물의 수를 기준으로 사용자를 주문하고 싶습니다. 관련 게시물을 찾고 사용자 쿼리에이 정보를 사용하려면 게시물을 검색해야합니다. 게시물이 별도로 색인화 된 경우에만 가능하며, 이는 게시물이 하위 문서 또는 중첩 필드 여야 함을 의미합니다.

게시물 자식 문서는 가정하면, 우리는이 같은 데이터를 프로토 타입 수 :

curl -XPOST 'http://localhost:9200/test-idx' -d '{ 
    "settings" : { 
     "number_of_shards" : 1, 
     "number_of_replicas" : 0 
    }, 
    "mappings" : { 
     "user" : { 
     "_source" : { "enabled" : true }, 
     "properties" : { 
      "full_name": { "type": "string" }, 
      "username": { "type": "string" } 
     } 
     }, 
     "post" : { 
     "_parent" : { 
      "type" : "user" 
     }, 
     "properties" : { 
      "title": { "type": "string"}, 
      "tags": { "type": "string", "boost": 10} 
     } 
     } 
    } 
}' && echo 

curl -XPUT 'http://localhost:9200/test-idx/user/1' -d '{ 
    "full_name": "First User", 
    "username": "firstymcfirsterton" 
}' && echo 
curl -XPUT 'http://localhost:9200/test-idx/user/2' -d '{ 
    "full_name": "Second User", 
    "username": "seconddude" 
}' && echo 

#Posts of the first user 
curl -XPUT 'http://localhost:9200/test-idx/post/1?parent=1' -d '{ 
    "title": "Puppies are Awesome", 
    "tags": ["dog house", "dog supplies", "dogs", "doggies", "hot dogs", "dog lovers", "dog"] 
}' && echo 
curl -XPUT 'http://localhost:9200/test-idx/post/2?parent=1' -d '{ 
    "title": "Cats are Awesome too", 
    "tags": ["cat", "cat supplies", "cats"] 
}' && echo 
curl -XPUT 'http://localhost:9200/test-idx/post/3?parent=1' -d '{ 
    "title": "One fine day with a woof and a purr", 
    "tags": ["catdog", "cartoons"] 
}' && echo 

#Posts of the second user 
curl -XPUT 'http://localhost:9200/test-idx/post/4?parent=2' -d '{ 
    "title": "Dogs are the best", 
    "tags": ["dog supperiority", "dog"] 
}' && echo 
curl -XPUT 'http://localhost:9200/test-idx/post/5?parent=2' -d '{ 
    "title": "Why dogs eat?", 
    "tags": ["dog diet", "canines"] 
}' && echo 
curl -XPUT 'http://localhost:9200/test-idx/post/6?parent=2' -d '{ 
    "title": "Who let the dogs out?", 
    "tags": ["dogs", "terrible music"] 
}' && echo 

curl -XPOST 'http://localhost:9200/test-idx/_refresh' && echo 

우리는 Top Children Query를 사용하여이 데이터를 조회 할 수 있습니다. 때문에 일치하는 태그에서 오는 엄청난 부스트 요소의 우선 첫 번째 사용자를 반환합니다

curl 'http://localhost:9200/test-idx/user/_search?pretty=true' -d '{ 
    "query": { 
    "top_children" : { 
     "type": "post", 
     "query" : { 
      "bool" : { 
       "should": [ 
        { "text" : { "title" : "dog" } }, 
        { "text" : { "tags" : "dog" } } 
       ] 
      } 
     }, 
     "score" : "sum" 
    } 
    } 
}' && echo 

이 쿼리 (또는 중첩 된 필드의 경우 우리는 Nested Query를 사용하여 유사한 결과를 얻을 수있다). 그래서, 그것은 당신이 원하는 것처럼 보이지 않을 수도 있지만 그것을 고정시키는 몇 가지 간단한 방법이 있습니다. 첫째, 태그 필드의 부스트 요인을 줄일 수 있습니다. 10은 여러 번 반복 될 수있는 분야에서 특히 큰 요소입니다. 또는 일치하는 하위 조회수를 완전히 무시하고 상위 일치 하위 문서 수를 점수로 사용하도록 쿼리를 수정할 수 있습니다.

curl 'http://localhost:9200/test-idx/user/_search?pretty=true' -d '{ 
    "query": { 
    "top_children" : { 
     "type": "post", 
     "query" : { 
      "constant_score" : { 
       "query" : {    
        "bool" : { 
         "should": [ 
          { "text" : { "title" : "dog" } }, 
          { "text" : { "tags" : "dog" } } 
         ] 
        } 
       } 
      } 
     }, 
     "score" : "sum" 
    } 
    } 
}' && echo