2016-09-15 1 views
0

다음 JSON 내가 요청으로 보낼 MVC에게 NEST 필요 무엇 올바른 JSON을 전송하지 :이 텍스트 노드가없는 (대신 전송되는 JSON이있다NEST의 허용량은

{ 
    "query": { 
    "multi_match": { 
     "text": { 
     "fields": "_all",    
     "query":  "monelo", 
     "fuzziness": "AUTO", 
     "operator": "and" 
     } 
    } 
    } 
} 

하고, 퍼지 결과를 다시 얻으려면 매우 중요합니다.)

{ 
    "query": { 
    "multi_match": { 
     "fields": "_all",    
     "query":  "monelo", 
     "fuzziness": "AUTO", 
     "operator": "and" 
    } 
    } 
} 

상기 JSON 생성과 함께 요청으로 전송된다 :

var productsQuery = 
client.Search<Elastic.Product>(s => s.Index(indexName).Type("products").Query(q => q.QueryString(qstr => qstr 
.Fields("_all") 
.Fuzziness(Fuzziness.Auto) 
.Query("*" + query + "*"))) 
.Size(100)); 

I 피들러와 디버깅 및 I 텍스트 노드에 추가하면 그때는 원하는 결과를 얻는다.

그래서 저는 올바르게하지 않거나 사용중인 NEST 클라이언트가 Elasticsearch REST의 최신 사양이 최신이 아닙니다.

문서를 공부하는 데 하루가 걸리지 않으면 몇 시간을 보냈으며 모든 쿼리 유형과 사용 가능한 각 속성을 문자 그대로 사용해 보았습니다.

LowLevelClient를 사용하여 raw json으로 요청을 시도했지만 검색된 결과를 여러 Elastic.Product 개체로 deserialize 할 수 없습니다.

+0

어떤 NEST 버전을 사용하고 있습니까? 어떤 Elasticsearch 버전을 타겟팅하고 있습니까? –

+0

@RussCam NEST 2.4.5 - 탄성 검색 2. – NullBy7e

답변

0

must와 should 절이있는 Bool 쿼리를 사용하여 해결되었습니다.

  var productsQuery = 
       client.Search<Elastic.Product>(s => s.Index(indexName).Type("products").Query(q => q.Bool(b => 
         b.Must(mq => mq.Fuzzy(f => f.Field("_all").Value(query.ToLower()).Fuzziness(Fuzziness.Auto))) 
         .Should(sq => sq.QueryString(sqqs => sqqs.DefaultField("_all").Query("*" + query.ToLower() + "*"))))) 
         .From(0) 
         .Size(100) 
         .Sort(ss => ss.Field(f => f.Field("displayName")))); 
관련 문제