Amplify を使用して Elasticsearch への Ajax 呼び出しを実行していますが、結果のフィルタリングに問題があります。すべてを URL として渡しているため、フォーマットする方法がわかりません。次の例では、searchCriteria として firstName:John を渡すと 4 つの結果が返されます。
self.url = "http://leServer:lePort/people/person/_search?q=" + self.searchCriteria;
firstName:John&lastName:Smith の場合、John 以外の名を持つ smith レコードが 2 つあるため、6 つの結果が返されます。
コマンド プロンプトから次のコマンドを実行すると、期待どおりの結果が得られます。
curl -XGET "http://leServer:lePort/people/person/_search?pretty=true" -d "{
\"query\": {
\"filtered\": {
\"query\": {
\"text\": {
\"firstName\": \"John\"
}
},
\"filter\": {
\"query\": {
\"text\": {
\"lastName\": \"Smith\"
}
}
}
}
}
}"
以下を Ajax 呼び出しとして使用しようとしましたが、何も返されません。\"
curlリクエストにあったも試してみました。
self.url = "http://leServer:lePort/people/person/_search?" +"-d"+"{query:{filtered:{query:{text:{firstName:John}},filter:{query:{text:{lastName:Smith}}}}}}"