ElasticSearch not failing but returning incorrect results

删除回忆录丶 提交于 2020-01-06 12:31:06

问题


I switched to POST searches using ajax in my application so I can start using the date range. However it seems no matter what I post it keeps returning the first 10 results in my index. The true results are in the 30k range.

    amplify.request.define("searchPostRequest", "ajax", {
        url: "http://leServer:9200/people/person/_search",
        type: "POST",
        dataType: 'jsonp',
        contentType: 'application/json'
    });
    self.advancedSearchPostQuery = {
        query: {
           term: {
               locationNumber:479
            }
        }
    };
    console.log(self.advancedSearchPostQuery);
    amplify.request({
        resourceId: "searchPostRequest",
        data: JSON.stringify(self.advancedSearchPostQuery),
        success: function (data) {
            console.log(data.hits.hits.length);
        }
    });

回答1:


If this is your actual code, your problem might simply be that your advancedSearchPostQuery isn't valid JSON.

You need to apply quotes:

advancedSearchPostQuery = {
    "query": {
        "term": {
            "locationNumber": 479
        }
    }
}

And I'm not sure if you need to stringify the object, but I'm not familiar with amplifyJS, so double check on that as well if amplifyjs is expecting an object or a string.

If that doesn't help check if your query returns the correct results when running from command line through curl.




回答2:


After doing more debugging I found that the request was being sent as a GET even though I had explicitly set it to post. Moving the data type to json, from jsonp let the request be sent as a POST, which resolved the issue. However this causes an issue in IE where the request is not sent at all due to the request being sent to another domain.

    amplify.request.define("searchPostRequest", "ajax", {
        url: "http://leServer:9200/people/person/_search",
        type: "POST",
        dataType: 'json',
        contentType: 'application/json'
    });


来源:https://stackoverflow.com/questions/14405886/elasticsearch-not-failing-but-returning-incorrect-results

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!