2014-12-27 3 views
2

elasticsearch를 사용하여 쿼리를 작성하는 데 어려움을 겪고 있습니다.Elasticsearch 와일드 카드로 OR 쿼리를 수행하는 방법

내가 좋아하는 뭔가를 조회 할 : 내가 만들려고 그래서

WHERE field_1 is 'match' $string OR field_2 is 'wildcard_match' $string OR field_3 is 'fuzzy' $string 

을이 같은 것입니다 :

{ 
    "bool" : { 
     "should" : [ 
      { 
       "match" : { "field_1" : "testing" } 
      }, 
      { 
       "wildcard" : { "field_2" : "*testing*" } 
      }, 
      { 
       "fuzzy" : { "field_3" : "testing" } 
      } 
     ], 
     "minimum_should_match" : 1, 
    } 
} 

하지만이 오류를 반환 것으로 보인다.

아무도 내가 이런 종류의 OR 쿼리를 elasticsearch와 어떻게 비교해야할까요?

내 현재 datasent :

{ 
    "_index": "twitter", 
    "_type": "tweet", 
    "_id": "1", 
    "_version": 1, 
    "found": true, 
    "_source": { 
    "field_1": "some data", 
    "field_2": "testing data", 
    "field_3": "other things" 
    } 
} 

내 쿼리 :

curl -XGET 'http://localhost:9200/twitter/tweet/_search' -d ' 
"query" : { 
    "bool" : { 
     "should" : [ 
      { 
       "match" : { "field_1" : "testing" } 
      }, 
      { 
       "wildcard" : { "field_2" : "*testing*" } 
      }, 
      { 
       "fuzzy" : { "field_3" : "testing" } 
      } 
     ], 
     "minimum_should_match" : 1, 
    } 
}' 

반환이 오류가 :

SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; 
    shardFailures {[ZmwpcILwSEyufHf-t9xQ6g][twitter][0]: 
    SearchParseException[[twitter][0]: from[-1],size[-1]: 
    Parse Failure [Failed to parse source [ 
     { 
     "query": { 
      "bool": { 
      "should": [ 
       { 
       "match": { 
        "field_1": "testing" 
       } 
       }, 
       { 
       "wildcard": { 
        "field_2": "*testing*" 
       } 
       }, 
       { 
       "fuzzy": { 
        "field_3": "testing" 
       } 
       } 
      ], 
      "minimum_should_match": 1, 
      } 
     } 
     } 
    ]]]; 
    nested: ElasticsearchParseException[Expected START_OBJECT but got VALUE_STRING null]; }{[ZmwpcILwSEyufHf-t9xQ6g][twitter][1]: 
    SearchParseException[[twitter][1]: from[-1],size[-1]: 
    Parse Failure [Failed to parse source [ 
     { 
     "query": { 
      "bool": { 
      "should": [ 
       { 
       "match": { 
        "field_1": "testing" 
       } 
       }, 
       { 
       "wildcard": { 
        "field_2": "*testing*" 
       } 
       }, 
       { 
       "fuzzy": { 
        "field_3": "testing" 
       } 
       } 
      ], 
      "minimum_should_match": 1, 
      } 
     } 
     } 
    ]]]; 
    nested: ElasticsearchParseException[Expected START_OBJECT but got VALUE_STRING null]; }{[ZmwpcILwSEyufHf-t9xQ6g][twitter][2]: 
    SearchParseException[[twitter][2]: from[-1],size[-1]: Parse Failure [Failed to parse source [ 
    { 
     "query": { 
     "bool": { 
      "should": [ 
      { 
       "match": { 
       "field_1": "testing" 
       } 
      }, 
      { 
       "wildcard": { 
       "field_2": "*testing*" 
       } 
      }, 
      { 
       "fuzzy": { 
       "field_3": "testing" 
       } 
      } 
      ], 
      "minimum_should_match": 1, 
     } 
     } 
    } 
    ]]]; 
    nested: ElasticsearchParseException[Expected START_OBJECT but got VALUE_STRING null]; }{[ZmwpcILwSEyufHf-t9xQ6g][twitter][3]: 
    SearchParseException[[twitter][3]: from[-1],size[-1]: Parse Failure [Failed to parse source [ 
    { 
     "query": { 
     "bool": { 
      "should": [ 
      { 
       "match": { 
       "field_1": "testing" 
       } 
      }, 
      { 
       "wildcard": { 
       "field_2": "*testing*" 
       } 
      }, 
      { 
       "fuzzy": { 
       "field_3": "testing" 
       } 
      } 
      ], 
      "minimum_should_match": 1, 
     } 
     } 
    } 
    ]]]; 
    nested: ElasticsearchParseException[Expected START_OBJECT but got VALUE_STRING null]; }{[ZmwpcILwSEyufHf-t9xQ6g][twitter][4]: 
    SearchParseException[[twitter][4]: from[-1],size[-1]: Parse Failure [Failed to parse source [ 
    { 
     "query": { 
     "bool": { 
      "should": [ 
      { 
       "match": { 
       "field_1": "testing" 
       } 
      }, 
      { 
       "wildcard": { 
       "field_2": "*testing*" 
       } 
      }, 
      { 
       "fuzzy": { 
       "field_3": "testing" 
       } 
      } 
      ], 
      "minimum_should_match": 1, 
     } 
     } 
    } 
    ]]]; nested: ElasticsearchParseException[Expected START_OBJECT but got VALUE_STRING null]; }] 
+0

반환되는 오류는 무엇입니까? – Jordan

+0

@Jordan 데이터 집합에 대한 더 많은 정보를 포함하도록 질문을 수정했으며 오류가 반환되었습니다. –

답변

2

이 나쁜 JSON 형식 때문이다. 이 쿼리의 올바른 JSON 형식은 다음과 같습니다. -

{ // --->> This was missing 
    "query": { 
    "bool": { 
     "should": [ 
     { 
      "match": { 
      "field_1": "testing" 
      } 
     }, 
     { 
      "wildcard": { 
      "field_2": "*testing*" 
      } 
     }, 
     { 
      "fuzzy": { 
      "field_3": "testing" 
      } 
     } 
     ], 
     "minimum_should_match": 1 
    } 
    } 
} // --->> This was missing