Elasticsearch - query exact value in array so that documents containing that value+others are not returned












0















I'm trying to create a query to search for a value that will return only the documents that have that exact value (even if repeated in the array) and no other documents (even if there's 1 entry of the value in the array). So, "bar" : [ "A", "A"] would be eligible but not "bar" : [ "A", "B"]



Example of a dataset:



"loren" : [
{
"id" : "1",
"foo": [{"bar": "A"},{"bar": "A"}]
},
{
"id" : "2",
"foo": [{"bar": "A"},{"bar": "B"}]
},
]


Example of the output I would expect:



"hits": {
"total": 1,
"max_score": 0.3666863,
"hits": [
{
"_index": "loren",
"_type": "loren",
"_id": "2",
"_score": 0.3666863,
"_source": {
"foo": [
{
"bar": "A"
},
{
"bar": "A"
}
]
}
}
]
}









share|improve this question





























    0















    I'm trying to create a query to search for a value that will return only the documents that have that exact value (even if repeated in the array) and no other documents (even if there's 1 entry of the value in the array). So, "bar" : [ "A", "A"] would be eligible but not "bar" : [ "A", "B"]



    Example of a dataset:



    "loren" : [
    {
    "id" : "1",
    "foo": [{"bar": "A"},{"bar": "A"}]
    },
    {
    "id" : "2",
    "foo": [{"bar": "A"},{"bar": "B"}]
    },
    ]


    Example of the output I would expect:



    "hits": {
    "total": 1,
    "max_score": 0.3666863,
    "hits": [
    {
    "_index": "loren",
    "_type": "loren",
    "_id": "2",
    "_score": 0.3666863,
    "_source": {
    "foo": [
    {
    "bar": "A"
    },
    {
    "bar": "A"
    }
    ]
    }
    }
    ]
    }









    share|improve this question



























      0












      0








      0








      I'm trying to create a query to search for a value that will return only the documents that have that exact value (even if repeated in the array) and no other documents (even if there's 1 entry of the value in the array). So, "bar" : [ "A", "A"] would be eligible but not "bar" : [ "A", "B"]



      Example of a dataset:



      "loren" : [
      {
      "id" : "1",
      "foo": [{"bar": "A"},{"bar": "A"}]
      },
      {
      "id" : "2",
      "foo": [{"bar": "A"},{"bar": "B"}]
      },
      ]


      Example of the output I would expect:



      "hits": {
      "total": 1,
      "max_score": 0.3666863,
      "hits": [
      {
      "_index": "loren",
      "_type": "loren",
      "_id": "2",
      "_score": 0.3666863,
      "_source": {
      "foo": [
      {
      "bar": "A"
      },
      {
      "bar": "A"
      }
      ]
      }
      }
      ]
      }









      share|improve this question
















      I'm trying to create a query to search for a value that will return only the documents that have that exact value (even if repeated in the array) and no other documents (even if there's 1 entry of the value in the array). So, "bar" : [ "A", "A"] would be eligible but not "bar" : [ "A", "B"]



      Example of a dataset:



      "loren" : [
      {
      "id" : "1",
      "foo": [{"bar": "A"},{"bar": "A"}]
      },
      {
      "id" : "2",
      "foo": [{"bar": "A"},{"bar": "B"}]
      },
      ]


      Example of the output I would expect:



      "hits": {
      "total": 1,
      "max_score": 0.3666863,
      "hits": [
      {
      "_index": "loren",
      "_type": "loren",
      "_id": "2",
      "_score": 0.3666863,
      "_source": {
      "foo": [
      {
      "bar": "A"
      },
      {
      "bar": "A"
      }
      ]
      }
      }
      ]
      }






      elasticsearch






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 22 '18 at 23:19







      bsferreira

















      asked Nov 21 '18 at 10:06









      bsferreirabsferreira

      60021025




      60021025
























          2 Answers
          2






          active

          oldest

          votes


















          1














          You can make use of the below Script Query for what you are looking for.



          Note that the field bar should be of type keyword.



          POST <your_search_index>/_search
          {
          "query": {
          "bool" : {
          "filter" : {
          "script" : {
          "script" : {
          "source" : """
          List myList = doc['bar'];
          int size = myList.size();
          int count = Collections.frequency(myList,params.token);
          if(count==size)
          return true;
          """,
          "lang" : "painless",
          "params": {
          "token": "test"
          }
          }
          }
          }
          }
          }
          }


          What you would get in the response is list of documents with the field bar having only test as its value/values.



          Note that if your mapping is created dynamically, you can try with bar.keyword in the above query.



          Let me know if it helps!






          share|improve this answer
























          • thank you for trying to help, I've tried that approach but it didn't work as expected. Also I think that using a query directly would have better performance. Here's is an example of a dataset and query using oracle (sqlfiddle.com/#!4/dd338/5). The problem is that I don't have enough knowledge regarding elasticsearch to convert that example, can you help?

            – bsferreira
            Nov 22 '18 at 9:49











          • Sure, but could you please post what you've observed in results and what you were expecting. Looking at your question, the above query works correctly. Meanwhile I'll check the link.

            – Kamal
            Nov 22 '18 at 10:13













          • @bsferreira The link you've mentioned has multiple joins, which won't work in ES. Could you post your mapping details how your index looks like, I can probably create a query based on your mapping details similar to the link you've mentioned.

            – Kamal
            Nov 22 '18 at 10:25











          • @bsferreira hey I am in that link. Sorry I've had some work earlier. let me know once you see my messages I've sent in that link.

            – Kamal
            Nov 22 '18 at 12:10



















          1














          @Kamal thank you for the enlightening. That lead me to the answer I think... but let me know your thoughts.



          When filtering the arrays, looks like by doing doc['foo.bar'].size();, elasticsearch makes a count(distinct ...) sql-equivalent and returns size n for arrays with n distinct values.



          working query example:



          GET /loren/_search 
          {
          "_source":[
          "foo.bar"
          ],
          "query":{
          "bool":{
          "must":[
          {
          "match":{
          "foo.bar":"A"
          }
          }
          ],
          "filter":{
          "script":{
          "script":{
          "source":"1==doc['foo.bar'].size();",
          "lang":"painless"
          }
          }
          }
          }
          }
          }





          share|improve this answer


























          • Yes, that's correct. I was wondering why my solution wasn't working in your machine Bummer :(. After the discussion we've had, the solution I've tried still worked as expected. :( Notice that my solution checks for word called test. If you look at it, it checks the word test which I've passed in params.token. Did you change this value test to SMT or DU and gave it a try. I'm sure it would be working as expected.

            – Kamal
            Nov 23 '18 at 6:36













          • { "source" : """ List myList = doc['functions.brandCode.keyword']; int size = myList.size(); int count = Collections.frequency(myList,params.token); if(count==size) return true; """, "lang" : "painless", "params": { "token": "SMT" } }

            – Kamal
            Nov 23 '18 at 6:41











          • Regardless, your solutions looks good :-). Go ahead and accept it, but do upvote my answer if you haven't ;-). And do let me know if you still have any queries.

            – Kamal
            Nov 23 '18 at 6:47






          • 1





            I tried your solution and even making some little tweaks to it but it didn't work as expected. I've upvoted your answer because it actually helped a lot. Thank you, you're very kind!

            – bsferreira
            Nov 23 '18 at 9:58











          • Well, in the end, I'm glad you got your solution!! :)

            – Kamal
            Nov 23 '18 at 10:05











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53409614%2felasticsearch-query-exact-value-in-array-so-that-documents-containing-that-val%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          You can make use of the below Script Query for what you are looking for.



          Note that the field bar should be of type keyword.



          POST <your_search_index>/_search
          {
          "query": {
          "bool" : {
          "filter" : {
          "script" : {
          "script" : {
          "source" : """
          List myList = doc['bar'];
          int size = myList.size();
          int count = Collections.frequency(myList,params.token);
          if(count==size)
          return true;
          """,
          "lang" : "painless",
          "params": {
          "token": "test"
          }
          }
          }
          }
          }
          }
          }


          What you would get in the response is list of documents with the field bar having only test as its value/values.



          Note that if your mapping is created dynamically, you can try with bar.keyword in the above query.



          Let me know if it helps!






          share|improve this answer
























          • thank you for trying to help, I've tried that approach but it didn't work as expected. Also I think that using a query directly would have better performance. Here's is an example of a dataset and query using oracle (sqlfiddle.com/#!4/dd338/5). The problem is that I don't have enough knowledge regarding elasticsearch to convert that example, can you help?

            – bsferreira
            Nov 22 '18 at 9:49











          • Sure, but could you please post what you've observed in results and what you were expecting. Looking at your question, the above query works correctly. Meanwhile I'll check the link.

            – Kamal
            Nov 22 '18 at 10:13













          • @bsferreira The link you've mentioned has multiple joins, which won't work in ES. Could you post your mapping details how your index looks like, I can probably create a query based on your mapping details similar to the link you've mentioned.

            – Kamal
            Nov 22 '18 at 10:25











          • @bsferreira hey I am in that link. Sorry I've had some work earlier. let me know once you see my messages I've sent in that link.

            – Kamal
            Nov 22 '18 at 12:10
















          1














          You can make use of the below Script Query for what you are looking for.



          Note that the field bar should be of type keyword.



          POST <your_search_index>/_search
          {
          "query": {
          "bool" : {
          "filter" : {
          "script" : {
          "script" : {
          "source" : """
          List myList = doc['bar'];
          int size = myList.size();
          int count = Collections.frequency(myList,params.token);
          if(count==size)
          return true;
          """,
          "lang" : "painless",
          "params": {
          "token": "test"
          }
          }
          }
          }
          }
          }
          }


          What you would get in the response is list of documents with the field bar having only test as its value/values.



          Note that if your mapping is created dynamically, you can try with bar.keyword in the above query.



          Let me know if it helps!






          share|improve this answer
























          • thank you for trying to help, I've tried that approach but it didn't work as expected. Also I think that using a query directly would have better performance. Here's is an example of a dataset and query using oracle (sqlfiddle.com/#!4/dd338/5). The problem is that I don't have enough knowledge regarding elasticsearch to convert that example, can you help?

            – bsferreira
            Nov 22 '18 at 9:49











          • Sure, but could you please post what you've observed in results and what you were expecting. Looking at your question, the above query works correctly. Meanwhile I'll check the link.

            – Kamal
            Nov 22 '18 at 10:13













          • @bsferreira The link you've mentioned has multiple joins, which won't work in ES. Could you post your mapping details how your index looks like, I can probably create a query based on your mapping details similar to the link you've mentioned.

            – Kamal
            Nov 22 '18 at 10:25











          • @bsferreira hey I am in that link. Sorry I've had some work earlier. let me know once you see my messages I've sent in that link.

            – Kamal
            Nov 22 '18 at 12:10














          1












          1








          1







          You can make use of the below Script Query for what you are looking for.



          Note that the field bar should be of type keyword.



          POST <your_search_index>/_search
          {
          "query": {
          "bool" : {
          "filter" : {
          "script" : {
          "script" : {
          "source" : """
          List myList = doc['bar'];
          int size = myList.size();
          int count = Collections.frequency(myList,params.token);
          if(count==size)
          return true;
          """,
          "lang" : "painless",
          "params": {
          "token": "test"
          }
          }
          }
          }
          }
          }
          }


          What you would get in the response is list of documents with the field bar having only test as its value/values.



          Note that if your mapping is created dynamically, you can try with bar.keyword in the above query.



          Let me know if it helps!






          share|improve this answer













          You can make use of the below Script Query for what you are looking for.



          Note that the field bar should be of type keyword.



          POST <your_search_index>/_search
          {
          "query": {
          "bool" : {
          "filter" : {
          "script" : {
          "script" : {
          "source" : """
          List myList = doc['bar'];
          int size = myList.size();
          int count = Collections.frequency(myList,params.token);
          if(count==size)
          return true;
          """,
          "lang" : "painless",
          "params": {
          "token": "test"
          }
          }
          }
          }
          }
          }
          }


          What you would get in the response is list of documents with the field bar having only test as its value/values.



          Note that if your mapping is created dynamically, you can try with bar.keyword in the above query.



          Let me know if it helps!







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 21 '18 at 11:50









          KamalKamal

          1,8131920




          1,8131920













          • thank you for trying to help, I've tried that approach but it didn't work as expected. Also I think that using a query directly would have better performance. Here's is an example of a dataset and query using oracle (sqlfiddle.com/#!4/dd338/5). The problem is that I don't have enough knowledge regarding elasticsearch to convert that example, can you help?

            – bsferreira
            Nov 22 '18 at 9:49











          • Sure, but could you please post what you've observed in results and what you were expecting. Looking at your question, the above query works correctly. Meanwhile I'll check the link.

            – Kamal
            Nov 22 '18 at 10:13













          • @bsferreira The link you've mentioned has multiple joins, which won't work in ES. Could you post your mapping details how your index looks like, I can probably create a query based on your mapping details similar to the link you've mentioned.

            – Kamal
            Nov 22 '18 at 10:25











          • @bsferreira hey I am in that link. Sorry I've had some work earlier. let me know once you see my messages I've sent in that link.

            – Kamal
            Nov 22 '18 at 12:10



















          • thank you for trying to help, I've tried that approach but it didn't work as expected. Also I think that using a query directly would have better performance. Here's is an example of a dataset and query using oracle (sqlfiddle.com/#!4/dd338/5). The problem is that I don't have enough knowledge regarding elasticsearch to convert that example, can you help?

            – bsferreira
            Nov 22 '18 at 9:49











          • Sure, but could you please post what you've observed in results and what you were expecting. Looking at your question, the above query works correctly. Meanwhile I'll check the link.

            – Kamal
            Nov 22 '18 at 10:13













          • @bsferreira The link you've mentioned has multiple joins, which won't work in ES. Could you post your mapping details how your index looks like, I can probably create a query based on your mapping details similar to the link you've mentioned.

            – Kamal
            Nov 22 '18 at 10:25











          • @bsferreira hey I am in that link. Sorry I've had some work earlier. let me know once you see my messages I've sent in that link.

            – Kamal
            Nov 22 '18 at 12:10

















          thank you for trying to help, I've tried that approach but it didn't work as expected. Also I think that using a query directly would have better performance. Here's is an example of a dataset and query using oracle (sqlfiddle.com/#!4/dd338/5). The problem is that I don't have enough knowledge regarding elasticsearch to convert that example, can you help?

          – bsferreira
          Nov 22 '18 at 9:49





          thank you for trying to help, I've tried that approach but it didn't work as expected. Also I think that using a query directly would have better performance. Here's is an example of a dataset and query using oracle (sqlfiddle.com/#!4/dd338/5). The problem is that I don't have enough knowledge regarding elasticsearch to convert that example, can you help?

          – bsferreira
          Nov 22 '18 at 9:49













          Sure, but could you please post what you've observed in results and what you were expecting. Looking at your question, the above query works correctly. Meanwhile I'll check the link.

          – Kamal
          Nov 22 '18 at 10:13







          Sure, but could you please post what you've observed in results and what you were expecting. Looking at your question, the above query works correctly. Meanwhile I'll check the link.

          – Kamal
          Nov 22 '18 at 10:13















          @bsferreira The link you've mentioned has multiple joins, which won't work in ES. Could you post your mapping details how your index looks like, I can probably create a query based on your mapping details similar to the link you've mentioned.

          – Kamal
          Nov 22 '18 at 10:25





          @bsferreira The link you've mentioned has multiple joins, which won't work in ES. Could you post your mapping details how your index looks like, I can probably create a query based on your mapping details similar to the link you've mentioned.

          – Kamal
          Nov 22 '18 at 10:25













          @bsferreira hey I am in that link. Sorry I've had some work earlier. let me know once you see my messages I've sent in that link.

          – Kamal
          Nov 22 '18 at 12:10





          @bsferreira hey I am in that link. Sorry I've had some work earlier. let me know once you see my messages I've sent in that link.

          – Kamal
          Nov 22 '18 at 12:10













          1














          @Kamal thank you for the enlightening. That lead me to the answer I think... but let me know your thoughts.



          When filtering the arrays, looks like by doing doc['foo.bar'].size();, elasticsearch makes a count(distinct ...) sql-equivalent and returns size n for arrays with n distinct values.



          working query example:



          GET /loren/_search 
          {
          "_source":[
          "foo.bar"
          ],
          "query":{
          "bool":{
          "must":[
          {
          "match":{
          "foo.bar":"A"
          }
          }
          ],
          "filter":{
          "script":{
          "script":{
          "source":"1==doc['foo.bar'].size();",
          "lang":"painless"
          }
          }
          }
          }
          }
          }





          share|improve this answer


























          • Yes, that's correct. I was wondering why my solution wasn't working in your machine Bummer :(. After the discussion we've had, the solution I've tried still worked as expected. :( Notice that my solution checks for word called test. If you look at it, it checks the word test which I've passed in params.token. Did you change this value test to SMT or DU and gave it a try. I'm sure it would be working as expected.

            – Kamal
            Nov 23 '18 at 6:36













          • { "source" : """ List myList = doc['functions.brandCode.keyword']; int size = myList.size(); int count = Collections.frequency(myList,params.token); if(count==size) return true; """, "lang" : "painless", "params": { "token": "SMT" } }

            – Kamal
            Nov 23 '18 at 6:41











          • Regardless, your solutions looks good :-). Go ahead and accept it, but do upvote my answer if you haven't ;-). And do let me know if you still have any queries.

            – Kamal
            Nov 23 '18 at 6:47






          • 1





            I tried your solution and even making some little tweaks to it but it didn't work as expected. I've upvoted your answer because it actually helped a lot. Thank you, you're very kind!

            – bsferreira
            Nov 23 '18 at 9:58











          • Well, in the end, I'm glad you got your solution!! :)

            – Kamal
            Nov 23 '18 at 10:05
















          1














          @Kamal thank you for the enlightening. That lead me to the answer I think... but let me know your thoughts.



          When filtering the arrays, looks like by doing doc['foo.bar'].size();, elasticsearch makes a count(distinct ...) sql-equivalent and returns size n for arrays with n distinct values.



          working query example:



          GET /loren/_search 
          {
          "_source":[
          "foo.bar"
          ],
          "query":{
          "bool":{
          "must":[
          {
          "match":{
          "foo.bar":"A"
          }
          }
          ],
          "filter":{
          "script":{
          "script":{
          "source":"1==doc['foo.bar'].size();",
          "lang":"painless"
          }
          }
          }
          }
          }
          }





          share|improve this answer


























          • Yes, that's correct. I was wondering why my solution wasn't working in your machine Bummer :(. After the discussion we've had, the solution I've tried still worked as expected. :( Notice that my solution checks for word called test. If you look at it, it checks the word test which I've passed in params.token. Did you change this value test to SMT or DU and gave it a try. I'm sure it would be working as expected.

            – Kamal
            Nov 23 '18 at 6:36













          • { "source" : """ List myList = doc['functions.brandCode.keyword']; int size = myList.size(); int count = Collections.frequency(myList,params.token); if(count==size) return true; """, "lang" : "painless", "params": { "token": "SMT" } }

            – Kamal
            Nov 23 '18 at 6:41











          • Regardless, your solutions looks good :-). Go ahead and accept it, but do upvote my answer if you haven't ;-). And do let me know if you still have any queries.

            – Kamal
            Nov 23 '18 at 6:47






          • 1





            I tried your solution and even making some little tweaks to it but it didn't work as expected. I've upvoted your answer because it actually helped a lot. Thank you, you're very kind!

            – bsferreira
            Nov 23 '18 at 9:58











          • Well, in the end, I'm glad you got your solution!! :)

            – Kamal
            Nov 23 '18 at 10:05














          1












          1








          1







          @Kamal thank you for the enlightening. That lead me to the answer I think... but let me know your thoughts.



          When filtering the arrays, looks like by doing doc['foo.bar'].size();, elasticsearch makes a count(distinct ...) sql-equivalent and returns size n for arrays with n distinct values.



          working query example:



          GET /loren/_search 
          {
          "_source":[
          "foo.bar"
          ],
          "query":{
          "bool":{
          "must":[
          {
          "match":{
          "foo.bar":"A"
          }
          }
          ],
          "filter":{
          "script":{
          "script":{
          "source":"1==doc['foo.bar'].size();",
          "lang":"painless"
          }
          }
          }
          }
          }
          }





          share|improve this answer















          @Kamal thank you for the enlightening. That lead me to the answer I think... but let me know your thoughts.



          When filtering the arrays, looks like by doing doc['foo.bar'].size();, elasticsearch makes a count(distinct ...) sql-equivalent and returns size n for arrays with n distinct values.



          working query example:



          GET /loren/_search 
          {
          "_source":[
          "foo.bar"
          ],
          "query":{
          "bool":{
          "must":[
          {
          "match":{
          "foo.bar":"A"
          }
          }
          ],
          "filter":{
          "script":{
          "script":{
          "source":"1==doc['foo.bar'].size();",
          "lang":"painless"
          }
          }
          }
          }
          }
          }






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 22 '18 at 23:21

























          answered Nov 22 '18 at 22:59









          bsferreirabsferreira

          60021025




          60021025













          • Yes, that's correct. I was wondering why my solution wasn't working in your machine Bummer :(. After the discussion we've had, the solution I've tried still worked as expected. :( Notice that my solution checks for word called test. If you look at it, it checks the word test which I've passed in params.token. Did you change this value test to SMT or DU and gave it a try. I'm sure it would be working as expected.

            – Kamal
            Nov 23 '18 at 6:36













          • { "source" : """ List myList = doc['functions.brandCode.keyword']; int size = myList.size(); int count = Collections.frequency(myList,params.token); if(count==size) return true; """, "lang" : "painless", "params": { "token": "SMT" } }

            – Kamal
            Nov 23 '18 at 6:41











          • Regardless, your solutions looks good :-). Go ahead and accept it, but do upvote my answer if you haven't ;-). And do let me know if you still have any queries.

            – Kamal
            Nov 23 '18 at 6:47






          • 1





            I tried your solution and even making some little tweaks to it but it didn't work as expected. I've upvoted your answer because it actually helped a lot. Thank you, you're very kind!

            – bsferreira
            Nov 23 '18 at 9:58











          • Well, in the end, I'm glad you got your solution!! :)

            – Kamal
            Nov 23 '18 at 10:05



















          • Yes, that's correct. I was wondering why my solution wasn't working in your machine Bummer :(. After the discussion we've had, the solution I've tried still worked as expected. :( Notice that my solution checks for word called test. If you look at it, it checks the word test which I've passed in params.token. Did you change this value test to SMT or DU and gave it a try. I'm sure it would be working as expected.

            – Kamal
            Nov 23 '18 at 6:36













          • { "source" : """ List myList = doc['functions.brandCode.keyword']; int size = myList.size(); int count = Collections.frequency(myList,params.token); if(count==size) return true; """, "lang" : "painless", "params": { "token": "SMT" } }

            – Kamal
            Nov 23 '18 at 6:41











          • Regardless, your solutions looks good :-). Go ahead and accept it, but do upvote my answer if you haven't ;-). And do let me know if you still have any queries.

            – Kamal
            Nov 23 '18 at 6:47






          • 1





            I tried your solution and even making some little tweaks to it but it didn't work as expected. I've upvoted your answer because it actually helped a lot. Thank you, you're very kind!

            – bsferreira
            Nov 23 '18 at 9:58











          • Well, in the end, I'm glad you got your solution!! :)

            – Kamal
            Nov 23 '18 at 10:05

















          Yes, that's correct. I was wondering why my solution wasn't working in your machine Bummer :(. After the discussion we've had, the solution I've tried still worked as expected. :( Notice that my solution checks for word called test. If you look at it, it checks the word test which I've passed in params.token. Did you change this value test to SMT or DU and gave it a try. I'm sure it would be working as expected.

          – Kamal
          Nov 23 '18 at 6:36







          Yes, that's correct. I was wondering why my solution wasn't working in your machine Bummer :(. After the discussion we've had, the solution I've tried still worked as expected. :( Notice that my solution checks for word called test. If you look at it, it checks the word test which I've passed in params.token. Did you change this value test to SMT or DU and gave it a try. I'm sure it would be working as expected.

          – Kamal
          Nov 23 '18 at 6:36















          { "source" : """ List myList = doc['functions.brandCode.keyword']; int size = myList.size(); int count = Collections.frequency(myList,params.token); if(count==size) return true; """, "lang" : "painless", "params": { "token": "SMT" } }

          – Kamal
          Nov 23 '18 at 6:41





          { "source" : """ List myList = doc['functions.brandCode.keyword']; int size = myList.size(); int count = Collections.frequency(myList,params.token); if(count==size) return true; """, "lang" : "painless", "params": { "token": "SMT" } }

          – Kamal
          Nov 23 '18 at 6:41













          Regardless, your solutions looks good :-). Go ahead and accept it, but do upvote my answer if you haven't ;-). And do let me know if you still have any queries.

          – Kamal
          Nov 23 '18 at 6:47





          Regardless, your solutions looks good :-). Go ahead and accept it, but do upvote my answer if you haven't ;-). And do let me know if you still have any queries.

          – Kamal
          Nov 23 '18 at 6:47




          1




          1





          I tried your solution and even making some little tweaks to it but it didn't work as expected. I've upvoted your answer because it actually helped a lot. Thank you, you're very kind!

          – bsferreira
          Nov 23 '18 at 9:58





          I tried your solution and even making some little tweaks to it but it didn't work as expected. I've upvoted your answer because it actually helped a lot. Thank you, you're very kind!

          – bsferreira
          Nov 23 '18 at 9:58













          Well, in the end, I'm glad you got your solution!! :)

          – Kamal
          Nov 23 '18 at 10:05





          Well, in the end, I'm glad you got your solution!! :)

          – Kamal
          Nov 23 '18 at 10:05


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53409614%2felasticsearch-query-exact-value-in-array-so-that-documents-containing-that-val%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          Xamarin.form Move up view when keyboard appear

          Post-Redirect-Get with Spring WebFlux and Thymeleaf

          Anylogic : not able to use stopDelay()