elasticsearch 手工艺品分类检索,elasticsearch,liferay,crafter-cms,elasticsearch,Liferay,Crafter Cms" /> elasticsearch 手工艺品分类检索,elasticsearch,liferay,crafter-cms,elasticsearch,Liferay,Crafter Cms" />

elasticsearch 手工艺品分类检索

elasticsearch 手工艺品分类检索,elasticsearch,liferay,crafter-cms,elasticsearch,Liferay,Crafter Cms,CrafterCMS编辑蓝图展示了分类法在内容定位中的应用。使用文章的categories_o字段,我可以将0分配到4个类别。该字段的Elasticsearch索引如下所示: "categories_o" : { "item" : [ { "key" : "style", "value_smv" : &

CrafterCMS编辑蓝图展示了分类法在内容定位中的应用。使用文章的categories_o字段,我可以将0分配到4个类别。该字段的Elasticsearch索引如下所示:

      "categories_o" : {
        "item" : [
          {
            "key" : "style",
            "value_smv" : "Style"
          },
          {
            "key" : "technology",
            "value_smv" : "Technology"
          }
        ]
      },
    "assetCategoryIds" : [ "644879", "644884", "644889", "6207544", "6207546", "6207550" ],
如何搜索包含一个或多个类别的文章

Liferay的内置分类框架为类似字段创建Elasticsearch索引,如下所示:

      "categories_o" : {
        "item" : [
          {
            "key" : "style",
            "value_smv" : "Style"
          },
          {
            "key" : "technology",
            "value_smv" : "Technology"
          }
        ]
      },
    "assetCategoryIds" : [ "644879", "644884", "644889", "6207544", "6207546", "6207550" ],
然后,您可以使用Elasticsearch查询构造“术语”来搜索属于多个(而不仅仅是一个)类别的文档:

"query": { "bool": {
  "must": { "match_all": {} },
  "filter": {
    "bool": {
      "must": [
        {"terms": {"assetCategoryIds": ["644889","6207550"]}},
...

我正在寻找在CrafterCMS中执行相同搜索的方法。

您可以使用相同的查询,使用字段的完整路径:

"terms": {"categories_o.item.key": [...]}

我对它进行了测试,这个查询可以工作:

alias jcurl='curl -H "Content-Type: application/json"'
jcurl -sXPOST "localhost:9201/sample2-preview_v1/_search?pretty" -d '
{"size":1,"query":{"bool":{"must":[
{"terms":{"categories_o.item.key":["technology","style"]}}]}}}'