首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Elasticsearch刻面查询

Elasticsearch刻面查询
EN

Stack Overflow用户
提问于 2013-04-12 12:30:48
回答 1查看 134关注 0票数 0

我的文档结构

代码语言:javascript
复制
UserID, AnswerID[] (int array)
1 , [9,10,11,56,78,99]
2 , [10,11,56,78,99]
3 , [8,10,12,56, 79,99]
4 , [9,10,11,56,78,99]

如果我只想知道回答了9,56的用户的数量,我可以写一个查询。但我有两个列表

代码语言:javascript
复制
List A - 9,10,11
ListB - 56,78,99

回答9,56,9,78,9,99,10,56,10,78,10,99,11,56...

任何帮助我们都很感激,

谢谢。

EN

回答 1

Stack Overflow用户

发布于 2013-04-12 15:15:28

它可以在不使用列表的情况下工作:

代码语言:javascript
复制
# Print ES Version
curl 'http://localhost:9200/'

# Delete the index `testindex`
curl -XDELETE 'http://localhost:9200/testindex'

# Create the index `testindex`
curl -XPUT 'http://localhost:9200/testindex' -d '{
    "settings" : {
        "index" : {
            "number_of_shards" : 1,
            "number_of_replicas" : 0
        }
    }
}'

# Wait for yellow
curl -XGET 'http://localhost:9200/_cluster/health?wait_for_status=yellow'

# Index docs
curl -XPUT http://localhost:9200/testindex/type/1 -d '{ "listA":"value1", "listB":"value2" }'
curl -XPUT http://localhost:9200/testindex/type/2 -d '{ "listA":"value1", "listB":"value3" }'
curl -XPUT http://localhost:9200/testindex/type/3 -d '{ "listA":"value1", "listB":"value2" }'

# Refresh docs
curl -XPOST 'http://localhost:9200/testindex/_refresh'

# TermFacet
curl -XPOST 'http://localhost:9200/testindex/type/_search?pretty' -d '
{
   "query": { "match_all" : {} },
    "facets" : {
        "tag" : {
            "terms" : {
                "script_field" : "_source.listA + \" - \" + _source.listB"
            }
        }
    }   
}'

提供:

代码语言:javascript
复制
{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "failed" : 0
  },
  "hits" : {
    "total" : 3,
    "max_score" : 1.0,
    "hits" : [ {
      "_index" : "testindex",
      "_type" : "type",
      "_id" : "1",
      "_score" : 1.0, "_source" : { "listA":"value1", "listB":"value2" }
    }, {
      "_index" : "testindex",
      "_type" : "type",
      "_id" : "2",
      "_score" : 1.0, "_source" : { "listA":"value1", "listB":"value3" }
    }, {
      "_index" : "testindex",
      "_type" : "type",
      "_id" : "3",
      "_score" : 1.0, "_source" : { "listA":"value1", "listB":"value2" }
    } ]
  },
  "facets" : {
    "tag" : {
      "_type" : "terms",
      "missing" : 0,
      "total" : 0,
      "other" : -3,
      "terms" : [ {
        "term" : "value1 - value2",
        "count" : 2
      }, {
        "term" : "value1 - value3",
        "count" : 1
      } ]
    }
  }
}

但是我不知道什么时候用list...我很想知道这是不是可以做到……

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15963088

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档