使用bool内的OR运算符进行弹性搜索查询(Elastic Search Query using an OR operator inside a bool)
我需要构建一个简单的查询,该查询转换为条件,因为“年龄”介于40 - 60之间,“country”是US或IN。 我正在使用bool运算符搜索解决方案。
我尝试使用以下选项:
"bool": { "must": [ { "range": { "age": { "from": 40, "to": 60 } } }, { "terms": { "country": [ "US", "IN" ] } } ] }
但是这个查询并没有给我任何结果。 我在这里错过了什么吗?
谢谢! ķ
I need to build a simple query which translates to a condition as "age" is between 40 - 60 and "country" is US or IN . I am searching for a solution using a bool operator.
I tried with the below option:
"bool": { "must": [ { "range": { "age": { "from": 40, "to": 60 } } }, { "terms": { "country": [ "US", "IN" ] } } ] }
But this query is not giving me any result. Am I missing something here?
Thanks! K
原文:https://stackoverflow.com/questions/35272356
最满意答案
如果您遇到以下网址:
http://myurl.com/#/editUser/1
然后
$location.path()
会返回你:/editUser/1
这样你就可以将它分割到字符/
,得到第二个元素并在开头添加一个/
(因为split
会移除每个/
),如下所示:'/' + $location.path().split('/')[1]
它会返回给你:
/editUser
这也适用于你有以下URL的地方(它会返回你:
/configUser
):http://myurl.com/#/configUser/
If you are in the case where you have the following URL :
http://myurl.com/#/editUser/1
Then
$location.path()
will return you :/editUser/1
so you can split it on the character/
, get the second element and add a/
at the beginning (becausesplit
removes each/
) like this :'/' + $location.path().split('/')[1]
It will return you this :
/editUser
This also works in the case where you have the following URL (it will return you :
/configUser
) :http://myurl.com/#/configUser/
相关问答
更多-
Angular没有获取完整查询的方法。 您可以使用url()获取URL,然后提取查询字符串。 var queryString = $location.url().split('?')[1]; Angular don't have method to get the complete querysting. You can use url() to get the URL and then extract the querystring. var queryString = $location.url(). ...
-
使用AngularJS $位置从URL中的查询字符串获取值(Getting values from query string in an url using AngularJS $location)[2022-10-29]
不知道自从接受的答案是否已经改变,但是这是可能的。 $location.search()将返回键值对的对象,与查询字符串相同。 没有值的键只是存储在对象中。 在这种情况下,对象将是: {"test_user_bLzgB": true} 您可以使用$location.search().test_user_bLzgB直接访问此值 示例(具有较大的查询字符串): http : //fiddle.jshell.net/TheSharpieOne/yHv2p/4/show/?test_user_bLzgB&some ... -
当path包含查询字符串时,使用returnUrl重定向的问题(Issue with redirecting with returnUrl when path contains query string)[2022-04-23]
我最终以稍微不同的方式解决了这个问题。 我摆脱了returnUrl代码,这样我的拦截器的responseError看起来像这样: responseError: function (rejection) { if (rejection.status === 401 && $location.path() !== '/') { $location.path('/login'); } return $q.reject(rejection); } 然后我添加了以下内容: a ... -
AngularJS字符串比较(AngularJS string compare)[2024-02-03]
toUpperCase是一个函数,所以你需要像fileName.toUpperCase()一样调用它,否则你将比较函数。 toUpperCase is a function so you need to invoke it like fileName.toUpperCase() or else you will be comparing the functions. -
根据路径和查询字符串,使用mod_rewrite比较和重写URL(Compare and rewrite URL with mod_rewrite based on path and query string)[2022-04-17]
%n仅访问来自的反向引用 在当前条件下最后匹配的RewriteCond 。 这就是为什么你的%2在你的第一套规则中总是空洞的原因。 你的第二次尝试绕过了RewriteCond %1 !%2这个问题,但你不能在你的RewriteRule引用%2 ,因为它再次引用了最后一个匹配的RewriteCond 。 如果您正在运行Apache 2,那么使用负前瞻断言可以使用非常简单的方法: RewriteRule ^/([0-9]*)/some/path/script.jsf?someId=(?!$1(?:$|[^0-9 ... -
如果您遇到以下网址: http://myurl.com/#/editUser/1 然后$location.path()会返回你: /editUser/1这样你就可以将它分割到字符/ ,得到第二个元素并在开头添加一个/ (因为split会移除每个/ ),如下所示: '/' + $location.path().split('/')[1] 它会返回给你: /editUser 这也适用于你有以下URL的地方(它会返回你: /configUser ): http://myurl.com/#/configUse ...
-
最好使用$ stateProvider而不是$ routeProvider: (function () { var app = angular.module("myApp", ["ui.router"]); app.config(function($stateProvider) { var users = { name: 'users', url: '/users', ...
-
我怀疑问题是你使用$location.path('/results').search({q: q})设置路径和搜索参数$location.path('/results').search({q: q}) 。 这是在哈希之后追加/results ,然后将查询添加到URL。 您不应该这样做,因为您的jQuery表单提交已经在处理导航。 FWIW I solved this by using POST instead of GET in the referring form. This fixed the URL ...
-
如何使用Angularjs从json中删除字符串中的数字?(How to remove numbers in string from json using Angularjs?)[2022-08-11]
您可以通过调用showName函数来change branchName。 showName将负责从string中删除digits ng-options="branch.branchName as showName(branch.branchName) for branch in baseBranches" 码 $scope.showName = function(branchName ){ return branchName.replace(/\d+/g, '') } You could chan ... -
对于http请求,强烈建议在发送数据之前对其进行base64编码。 试试这段代码,看它是否有效: $http.get(apiUrl, { params: { username: "Emma", email: window.btoa("emma@watson.com"), password: "1234" } }) .success(function (data) { //do a simple return of the email o ...