在弹性搜索

时间:2016-04-06 23:28:19

标签: elasticsearch

我的文档结构如下:

curl -XPUT 'http://localhost:9200/fin/deal/1' -d '
{ 
    "deal_key": "500029871", 
    "dealname": "Babson CLO Ltd. 2004-I", 
    "dealPct": "5" ,
    "mvdm": "5" ,
}'

curl -XPUT 'http://localhost:9200/blog/post/1' -d '
{ 
    "deal_key": "500029871", 
    "dealname": "Babson CLO Ltd. 2004-I", 
    "dealPct": "5" ,
    "mvdm": "5" ,
}'

curl -XPUT 'http://localhost:9200/blog/post/1' -d '
{ 
    "deal_key": "500029871", 
    "dealname": "Babson CLO Ltd. 2004-I2", 
    "dealPct": "5" ,
    "mvdm": "5" ,
}'

如何从弹性搜索中的查询中获取不同的记录集:我的查询如下:

 {
    "_source": [
    "dealname",
    "deal_key"
    ],
    "query": {
    "match": {
    "dealname": {
    "query": "Babson 2004",
    "operator": "and"
    }
    }
    }
    }

我回来的结果是:

"_source": {
"dealname": "Babson CLO Ltd. 2004-I",
"deal_key": "500029871"
}

"_source": {
"dealname": "Babson CLO Ltd. 2004-I",
"deal_key": "500029871"
}

"_source": {
"dealname": "Babson CLO Ltd. 2004-I2",
"deal_key": "500029871"
}

但是如你所见,输出中只有2个不同的记录

  1. deal_key 500029871和dealname Babson CLO Ltd. 2004-I
  2. deal_key 500029871和dealname Babson CLO Ltd. 2004-I2
  3. 但输出给了我3个结果集。我怎样才能改进这个?

    在sql场景中,你可以假设我有一个包含4列的表,我试着在我的查询中只获得2列

    select distinct col1 ,col2 from table1 where col2 = 'xyz'
    

0 个答案:

没有答案