2014-12-27 7 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 
Смежные вопросы