SOLR count multi valued fields query

喜你入骨 提交于 2019-12-12 03:09:42

问题


Is it possible to create a solr query where only documents are returned which have more than one entries in a multi valued field. For example:

docs: [
  {
    id: 1,
    myfield: ["hello word", "hello stackoverflow"]
  },
  {
    id: 2,
    myfield: ["hello word"]
  }
]

And my naive sample query just for explanation what I want:

/select?q=count(myfield.length, 'eq', 2)

回答1:


Yes it is but not "out of the box". A solution in order to achieve what you're looking for is to use CountFieldValuesUpdateProcessorFactory along with a new field called in your case myfield_count. For instance:

docs: [
  {
    id: 1,
    myfield: ["hello word", "hello stackoverflow"]
    myfield_count: 2
  },
  {
    id: 2,
    myfield: ["hello word"]
    myfield_count: 1
  }
]

After that you can simply use a boolean function in order to filter or score for myfield_count>1.



来源:https://stackoverflow.com/questions/38769405/solr-count-multi-valued-fields-query

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