我是elasticsearch的新手,我正在使用版本5.1.2。 我有这个索引,我不知道如果我用_source字段创建得很好。 我想要一个返回所有寄存器的查询,其中loc = XXY和part = Z,我该怎么办呢?我正在尝试这个但不行。有什么想法吗?
Button.Click
我正在使用但不起作用的查询:
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 107271,
"max_score": 1,
"hits": [
{
"_index": "my_index",
"_type": "po",
"_id": "0",
"_score": 1,
"_source": {
"loc": "XXX",
"part": "YY",
"order_qty": "16",
}
},
{
"_index": "my_index",
"_type": "po",
"_id": "14",
"_score": 1,
"_source": {
"loc": "XXY",
"part": "Z",
"order_qty": "7",
}
},
{
"_index": "my_index",
"_type": "po",
"_id": "19",
"_score": 1,
"_source": {
"loc": "XXY",
"part": "Z",
"order_qty": "8",
}
...
映射:
GET my_index/po/_search
{
"query" : {
"term" : { "loc" : "XXY", "part": "Z"}
}
}
答案 0 :(得分:1)
你应该这样做:
POST my_index/po/_search
{
"query": {
"bool": {
"must": [
{ "match": { "loc": "XXY" }},
{ "match": { "part": "Z" }}
]
}
}
}
有关匹配查询的一些其他信息 - https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html