minjay26
敬畏每一行代码

1 搜索所有文档中还有某个字段的方法: localhost:9200/get-together/group/_search?pretty

{
"query": {
"query_string": {
"query": "elasticsearch"
}
}
}

结果为

{
"took": 2,
"timed_out": false,
"_shards": {
"total": 2,
"successful": 2,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 1.3782532,
"hits": [
{
"_index": "get-together",
"_type": "group",
"_id": "3",
"_score": 1.3782532,
"_source": {
"name": "Elasticsearch San Francisco",
"organizer": "Mik",
"description": "Elasticsearch group for ES users of all knowledge levels",
"created_on": "2012-08-07",
"tags": [
"elasticsearch"
,
"big data"
,
"lucene"
,
"open source"
],
"members": [
"Lee"
,
"Igor"
],
"location_group": "San Francisco, California, USA"
}
}
,
{
"_index": "get-together",
"_type": "group",
"_id": "2",
"_score": 0.10344465,
"_source": {
"name": "Elasticsearch Denver",
"organizer": "Lee",
"description": "Get together to learn more about using Elasticsearch, the applications and neat things you can do with ES!",
"created_on": "2013-03-15",
"tags": [
"denver"
,
"elasticsearch"
,
"big data"
,
"lucene"
,
"solr"
],
"members": [
"Lee"
,
"Mike"
],
"location_group": "Denver, Colorado, USA"
}
}
]
}
}

只要某个文档中还有该字段都会被查出,也可以设置 " default_field ": " name ","default_operator": "AND",and表示只有当某文档中出现搜索的完整字段才会匹配,例如 localhost:9200/get-together/group/_search?pretty

{
"query": {
"query_string": {
"query": "elasticsearch san francisco",
"default_field": "name",
"default_operator": "AND"
}
}
}

也可以设置为"default_operator": "OR",就是当出现elasticsearche san francisco某一个字段都会匹配被查出,另外一种可以实现该结果的查询是: "query": "name:elasticsearch AND name:san AND name:francisco"




posted on 2017-04-07 10:35  minjay26  阅读(172)  评论(0编辑  收藏  举报