Uploaded image for project: 'PUBLIC - Liferay Portal Community Edition'
  1. PUBLIC - Liferay Portal Community Edition
  2. LPS-87304

Support painless script in Liferay Search Framework

    Details

      Description

      Background:
      While working on LPS-85972 we've run into 2 use cases in which it would be necessary to use a painless script while doing a search using the Liferay Search Framework:

      Use case 1:
      Return documents in which all elements in the assetTagNames array match a certain condition (e.g: Given the following set of Journal Articles, get the journal articles where all elements in the array contain substring keyword1).
      Document1: {..., "assetTagNames": ["keyword11","keyword12"],..}
      Document2: {..., "assetTagNames": ["keyword11","keyword22"],..}
       
      The query should return document1 but not document2.

      Such query requires passing a painless script as follows:

       

      POST _search
      {
        "query": {
          "bool" : {
            "must" : [
              {
               "wildcard" : { "assetTagNames.raw" : "*keyword1*"}        
              },
             {
              "script" : {
                "script" : {
                  "inline" : "doc['assetTagNames.raw'].getValues().stream().allMatch(s -> s.contains('keyword1'));",
                  "lang" : "painless"
                }
              }
            }
            ]
          }
        }
      }
      

       

      Use case 2:
      Return documents in which the assetTagNames array contains exactly the following set of keywords (all of them and not more)
      (e.g: Given the following set of Journal Articles, get the journal articles where "assetTagNames" is exactly ["keyword11","keyword12"]). 
      Document1: {..., "assetTagNames": ["keyword11","keyword12"],..}
      Document2: {..., "assetTagNames": ["keyword11","keyword22"],..}
      Document3: {..., "assetTagNames": ["keyword11","keyword12","keyword13"],..} 
      The query should return document1 but not document2 and not document3.

      Such query also requires passing a painless script as follows:

      POST _search
      {
         "query":{
            "bool":{
               "must":[
                  {
                     "term":{
                        "assetTagNames.raw":"keyword11"
                     }
                  },
                  {
                     "term":{
                        "assetTagNames.raw":"keyword12"
                     }
                  },
                  {
                     "script":{
                        "script":{
                           "inline":"doc['assetTagNames.raw'].getValues().size() == 2;",
                           "lang":"painless"
                        }
                     }
                  }
               ]
            }
         },
         "stored_fields":[
            "localized_title_en_US",
            "assetTagNames"
         ]
      }
      

      Being able to use a painless script would allow to support use case 2 without having to index an additional field with the number of elements in the array.

       

       

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                support-lep@liferay.com SE Support
                Reporter:
                ruben.pulido Ruben Pulido
              • Votes:
                1 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:

                  Packages

                  Version Package