Versuchen, Python-elasticsearch oder curl zu erhalten, um die entsprechenden Ergebnisse bei der Verwendung von Bool und Must-Abfragen zurückzugeben.Elasticsearch 'müssen' Abfrage mit mehreren Kriterien
Ich weiß, das Dokument ist in meiner Abfrage, ich kann es mit "sollte" finden; Ich brauche jedoch beide Kriterien, um zu befriedigen, also versuche ich, die gleiche Frage mit "Muss" zu stellen. Wenn ich "muss" verwende, wird das fragliche Dokument nicht zurückgegeben.
Mit Should
$ curl -XGET 'localhost:9200/polarion/subtype1/_search?pretty' -H 'Content-Type: application/json' -d'
{
"query" : {
"constant_score" : {
"filter" : {
"bool" : {
"should" : [
{ "term" : {"project" : "AMQ"}},
{ "term" : {"test-type" : "functional"}}]
}
}
}
}
}
'
"hits" : {
"total" : 3,
"max_score" : 1.0,
"hits" : [
{
"_index" : "polarion",
"_type" : "subtype1",
"_id" : "AV3s-vbF8T4AI9Zj3GkM",
"_score" : 1.0,
"_source" : {
"project" : "AMQ",
"query" : "test-metrics",
"test-type" : "functional",
"2017-08-16" : 1916
}
},
mit MUST
$ curl -XGET 'localhost:9200/polarion/subtype1/_search?pretty' -H 'Content-Type: application/json' -d'
{
"query" : {
"constant_score" : {
"filter" : {
"bool" : {
"must" : [
{ "term" : {"project" : "AMQ"}},
{ "term" : {"test-type" : "functional"}}]
}
}
}
}
}
'
{ "took" : 0, "timed_out" : false, "_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0 }, "hits" : {
"total" : 0,
"max_score" : null,
"hits" : [ ] } }
ziemlich sicher ist es, weil das 'Projekt'-Feld analysiert wird (d. H. Es hat' Text'-Typ). Sie können stattdessen entweder zur 'match'-Abfrage wechseln oder bei' term' bleiben, aber nach 'amq' in Kleinbuchstaben anstelle von' AMQ' suchen – Val
Hinzufügen zu Vals Kommentar oben, oder Sie können Ihre Zuordnung von Textart zu Schlüsselwort ändern Geben Sie dann die Begriffe als ihren genauen Wert – Rahul