使用Ajax对elasticsearch的结果进行过滤

时间:2013-01-02 16:02:59

标签: ajax elasticsearch amplifyjs

我正在使用Amplify对elasticsearch进行Ajax调用,但是我在筛选结果时遇到了问题。由于我将所有内容都作为URL传递,因此我不确定如何格式化它。 当我传递firstName:John作为searchCriteria时,以下返回4个结果。

self.url = "http://leServer:lePort/people/person/_search?q=" + self.searchCriteria;

如果我有firstName:John& lastName:Smith,则返回6个结果,因为有2个smith记录,其名字不是John。

如果我从命令提示符运行以下命令,我会收到一个预期的结果。

curl -XGET "http://leServer:lePort/people/person/_search?pretty=true" -d "{
  \"query\": {
    \"filtered\": {
      \"query\": {
        \"text\": {
          \"firstName\": \"John\"
        }
      },
      \"filter\": {
        \"query\": {
          \"text\": {
            \"lastName\": \"Smith\"
          }
        }
      }
    }
  }
}"

我尝试使用以下作为我的Ajax调用,但它不会返回任何内容。我还尝试了卷曲请求所具有的\"

self.url = "http://leServer:lePort/people/person/_search?" +"-d"+"{query:{filtered:{query:{text:{firstName:John}},filter:{query:{text:{lastName:Smith}}}}}}"

1 个答案:

答案 0 :(得分:1)

查询应该是网址编码+firstName:John +lastName:Smith。顺便说一下,将弹性搜索服务器暴露给外界可能是一个坏主意。

相关问题