我正在使用ElasticSearch(在使用FosElasticaBundle的Symfony 4项目中),我不知道如何构建如下查询:
Match if value in list of values
我有一个字段"code"
,如果此字段"code"
的值为:"first or "second" or "third"
我尝试了条款:
"first AND "second" AND "third"
?"first or "second" or "third"
,一切都被检索到了,所以查询是没用的吗?我尝试使用Match(应该,必须)或逐个使用......没有...
那么,我怎样才能在elasticsearch中做到这一点?谢谢!
答案 0 :(得分:0)
PUT some-test
PUT /some-test/doc/1
{
"foo": "first"
}
PUT /some-test/doc/2
{
"foo": "second"
}
PUT /some-test/doc/3
{
"foo": "fourth"
}
POST some-test/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"foo": "first second third"
}
}
]
}
}
}
给了我
{
"took": 4,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 0.2876821,
"hits": [
{
"_index": "some-test",
"_type": "doc",
"_id": "2",
"_score": 0.2876821,
"_source": {
"foo": "second"
}
},
{
"_index": "some-test",
"_type": "doc",
"_id": "1",
"_score": 0.2876821,
"_source": {
"foo": "first"
}
}
]
}
}