2014-01-20 4 views
0

결과를 정렬하는 데 문제가 있습니다. ES에 넣어ElasticSearch - 정렬이 작동하지 않습니다.

다음
curl -X PUT localhost:9200/companies -d ' 
{ 
    "settings" : { 
    "analysis" : { 
     "analyzer" : { 
      "my_edge_ngram_analyzer" : { 
       "tokenizer" : "my_edge_ngram_tokenizer" 
      } 
      }, 
     "tokenizer" : { 
      "my_edge_ngram_tokenizer" : { 
       "type" : "edgeNGram", 
       "min_gram" : "1", 
        "max_gram" : "5", 
        "token_chars": [ "letter", "digit" ] 
      } 
     } 
    } 
    }, 
    "mappings": { 
    "company" : { 
     "properties" : { 
     "name" : { "type" : "string" }, 
     "count" : {"type" : "long" }, 
     "name_suggest" : { 
      "type" :  "completion", 
      "index_analyzer": "my_edge_ngram_analyzer", 
      "search_analyzer": "my_edge_ngram_analyzer" 
     } 
     } 
    } 
    } 
}' 

된다 예 :

curl -X PUT localhost:9200/companies/company/1 -d ' 
{ 
    "name" :   "1800flowers", 
    "count": 1000, 
    "name_suggest" : { 
    "input" :  [ 
     "1800 flowers.Com, Inc", 
     "1800 Flowers","1800-Flowers.com", 
     "1 800 Flowers", 
     "www.1800flowers.com", 
     "1800Flowers.com", 
     "Inc,1-800-FLOWERS.COM", 
     "1-800-FLOWERS.COM, INC", 
     "1800Flowers", 
     "1800Flowers Inc", 
     "1800Flowers.com (Consultant)", 
     "1-800-FLOWERS","1800Flowers.com", 
     "1800FLOWERS INTERNATIONAL", 
     "1-800 Flowers", 
     "1-800 FLOWERS.COM, INC", 
     "1-800-FLOWERS, Inc", 
     "1800 flowers.com", 
     "1-800Flowers.com", 
     "1-800 flowers.com", 
     "1800 Flowers Inc" 
    ], 
    "output" : "1800 Flowers" 
    } 
}' 

curl -X PUT localhost:9200/companies/company/2 -d ' 
{ 
    "name" :   "1800 Ruby", 
    "count": 10000, 
    "name_suggest" : { 
    "input" :  [ 
    "1800" 
    ], 
    "output" : "1800 Ruby" 
    } 
}' 
이제

I 1800에서 텍스트 검색을 할 경우 분명, 내가 출력을 제공, 다시 이러한 개체를 모두 얻어야한다 "아래 내 ​​설정이다 1800 꽃 ","1800 루비 ".

정말이 결과를 개수, 내림차순으로 정렬하여 "1800 Ruby", "1800 Flowers"가 있어야하지만 작동하지 않습니다.

curl -X POST localhost:9200/companies/_suggest -d ' 
{ 
    "query":{ 
    "companies" : { 
    "text" : "18", 
    "completion" : { 
     "field" : "name_suggest" 
    } 
    } 
    }, 
    "sort": [ {"count": {"order": "desc"} } ] 
}' 

답변

0

문서의 "name_suggest" 입력란에 가중치를 추가해야합니다. 또한 _suggest 요청에서 "query" 구문을 사용할 수 없습니다.

curl -XPUT "http://localhost:9200/companies/company/1" -d' 
{ 
    "name" :   "1800flowers", 
    "count": 1000, 
    "name_suggest" : { 
    "input" :  [ 
     "1800 flowers.Com, Inc", 
     "1800 Flowers","1800-Flowers.com", 
     "1 800 Flowers", 
     "www.1800flowers.com", 
     "1800Flowers.com", 
     "Inc,1-800-FLOWERS.COM", 
     "1-800-FLOWERS.COM, INC", 
     "1800Flowers", 
     "1800Flowers Inc", 
     "1800Flowers.com (Consultant)", 
     "1-800-FLOWERS","1800Flowers.com", 
     "1800FLOWERS INTERNATIONAL", 
     "1-800 Flowers", 
     "1-800 FLOWERS.COM, INC", 
     "1-800-FLOWERS, Inc", 
     "1800 flowers.com", 
     "1-800Flowers.com", 
     "1-800 flowers.com", 
     "1800 Flowers Inc" 
    ], 
    "output" : "1800 Flowers", 
    "weight" : 1000 
    } 
}' 

curl -XPUT "http://localhost:9200/companies/company/2" -d' 
{ 
    "name" :   "1800 Ruby", 
    "count": 10000, 
    "name_suggest" : { 
    "input" :  [ 
    "1800" 
    ], 
    "output" : "1800 Ruby", 
    "weight" : 10000 
    } 
}' 

을 그리고 정상적인 요청을

curl -XPOST "http://localhost:9200/companies/_suggest" -d' 
{ 
    "companies": { 
     "text": "18", 
     "completion": { 
      "field": "name_suggest" 
     } 
     } 
}' 
을 제안 :

따라서, 동일한 설정을 사용하여 위가 매핑, 다음과 같이 나는 "count" 동일 SUGGESTER 무게로 문서를 업데이트 할 수 있습니다

여기
{ 
    "_shards": { 
     "total": 1, 
     "successful": 1, 
     "failed": 0 
    }, 
    "companies": [ 
     { 
     "text": "18", 
     "offset": 0, 
     "length": 2, 
     "options": [ 
      { 
       "text": "1800 Ruby", 
       "score": 10000 
      }, 
      { 
       "text": "1800 Flowers", 
       "score": 1000 
      } 
     ] 
     } 
    ] 
} 

가 예상되는 결과를 얻을 전체 실행 가능한 예 : http://sense.qbox.io/gist/21cac07480e4077e083b037c5ac00016b04503f2

+0

잘 작동하는 것 같습니다. 단순히 count 속성을 두 번 쓰는 대신 참조하는 방법을 알고 있습니까? – redrubia

+0

슬프게도 아니오, 찾을 수 없었습니다. 완성의 한계 중 하나는 내가 알 수있는 한 제안합니다. –

관련 문제