我有以下映射:
<tbody>
<form action="update_quantity.php" method="post" class="c-shop-form-1">
<?php while ($row = mysqli_fetch_array($query)) {
$id2=$row['id'];
echo "<tr><td>{$row['name']}</td>
<td>
<input type='text' class='form-control c-square c-theme' style='width: 90px;' placeholder='Quantity' name='Quantity' id='Quantity'>
</td>
<td>
<input type='text' class='form-control c-square c-theme' style='width: 90px;' placeholder='Quantity' name='Quantity2' id='Quantity2'>
</td>
</tr>";
}?>
<tr>
<td></td>
<td></td>
<td><button type="submit" name="RCV" id="RCV" value="submit" class="btn c-theme-btn c-btn-square center c-btn-bold c-btn-uppercase">Submit</button></td>
</tr>
</form>
</tbody>
并执行简单查询:
{
cities: {
mappings: {
city: {
properties: {
id: {
type: "long"
},
name: {
type: "text",
fields: {
keyword: {
type: "keyword",
ignore_above: 256
}
}
},
population: {
type: "long"
},
}
}
}
}
}
所以我得到的结果是:
{
query: {
bool: {
must_not: { match: { name: 'New York' } },
},
},
size: 2,
}
如何限制此查询以匹配{
"took": 5,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 10385,
"max_score": 1,
"hits": [
{
"_index": "cities",
"_type": "city",
"_id": "14",
"_score": 1,
"_source": {
"name": "Berlin",
"id": 14,
"population": 7293
}
},
{
"_index": "cities",
"_type": "city",
"_id": "19",
"_score": 1,
"_source": {
"name": "Paris",
"id": 19,
"population": 25018
}
}
]
}
}
在特定数组值中的文档,即name
?
我正在寻找类似于SQL语句的东西:
['Berlin', 'Bonn', 'Munchen']
答案 0 :(得分:1)
您可以使用terms query,因此您的查询应如下所示:
{
query: {
bool: {
must: { terms: { 'name.keyword': ['Berlin', 'Bonn', 'Munchen'] } }
must_not: { match: { name: 'New York' } },
},
},
size: 2,
}
答案 1 :(得分:0)
POST /cities/_search
{
"query": {
"bool" : {
"must" : [
{ "match" : { "name" : "Berlin" } },
{ "match" : { "name" : "Munchen" } },
{ "match" : { "name" : "Bonn" } }
],
"minimum_should_match" : 3
}
}
}
或
POST /cities/_search
{
"query": {
"bool" : {
"must" : [
{ "term" : { "name.keyword" : "Berlin" } },
{ "term" : { "name.keyword" : "Munchen" } },
{ "term" : { "name.keyword" : "Bonn" } }
],
"minimum_should_match" : 3
}
}
}