Точное совпадение Query in Elasti c Поиск вопроса - PullRequest
0 голосов
/ 12 февраля 2020

У меня есть index in ElasticSearch с 4 данными

Вот данные:

{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 4,
      "relation": "eq"
    },
    "max_score": 1,
    "hits": [
      {
        "_index": "sample4",
        "_type": "logs",
        "_id": "UQBMOHABHstawU4w4_z3",
        "_score": 1,
        "_source": {
          "date": "2020-02-12T07:28:48",
          "target": {
            "http://localhost/wordpress/index.php/2020/01/13/hello-world/": {
              "clicks": {
                "868 278": 12
              }
            }
          }
        }
      },
      {
        "_index": "sample4",
        "_type": "logs",
        "_id": "UgBNOHABHstawU4wT_wn",
        "_score": 1,
        "_source": {
          "date": "2020-02-12T07:29:15",
          "target": {
            "http://localhost/wordpress/": {
              "clicks": {
                "958 250": 5
              }
            }
          }
        }
      },
      {
        "_index": "sample4",
        "_type": "logs",
        "_id": "UABMOHABHstawU4wC_y9",
        "_score": 1,
        "_source": {
          "date": "2020-02-12T07:27:52",
          "target": {
            "http://localhost/wordpress/": {
              "clicks": {
                "880 257": 6
              }
            }
          }
        }
      },
      {
        "_index": "sample4",
        "_type": "logs",
        "_id": "UwBOOHABHstawU4wFvxV",
        "_score": 1,
        "_source": {
          "date": "2020-02-12T07:30:06",
          "target": {
            "http://localhost/wordpress/index.php/2020/01/13/hello-world/": {
              "clicks": {
                "389 60": 33
              }
            },
            "http://localhost/wordpress/": {
              "clicks": {
                "657 235": 8
              }
            }
          }
        }
      }
    ]
  }
}

Я хочу сопоставить ключ target в индексе со значением http://localhost/wordpress/. Если данное значение точно совпадает со значением в ключе target в индексе ES, я бы получил 3 данных. Внутри целевого ключа это было похоже на объект. Так что я не знаю, как сделать запрос на совпадение.

Вот запрос, который я пробовал:

{
    "query": {
        "wildcard": {
            "target.http://localhost/wordpress/": {
                "value": "*"
            }
        }
    }
}

Но он возвращает 0 результатов. Вывод, который я получил:

  {
      "took": 1,
      "timed_out": false,
      "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
      },
      "hits": {
        "total": {
          "value": 0,
          "relation": "eq"
        },
        "max_score": null,
        "hits": []
      }
    }

Требуемый вывод:

{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 3,
      "relation": "eq"
    },
    "max_score": 1,
    "hits": [
      {
        "_index": "sample4",
        "_type": "logs",
        "_id": "UgBNOHABHstawU4wT_wn",
        "_score": 1,
        "_source": {
          "date": "2020-02-12T07:29:15",
          "target": {
            "http://localhost/wordpress/": {
              "clicks": {
                "958 250": 5
              }
            }
          }
        }
      },
      {
        "_index": "sample4",
        "_type": "logs",
        "_id": "UABMOHABHstawU4wC_y9",
        "_score": 1,
        "_source": {
          "date": "2020-02-12T07:27:52",
          "target": {
            "http://localhost/wordpress/": {
              "clicks": {
                "880 257": 6
              }
            }
          }
        }
      },
      {
        "_index": "sample4",
        "_type": "logs",
        "_id": "UwBOOHABHstawU4wFvxV",
        "_score": 1,
        "_source": {
          "date": "2020-02-12T07:30:06",
          "target": {
            "http://localhost/wordpress/index.php/2020/01/13/hello-world/": {
              "clicks": {
                "389 60": 33
              }
            },
            "http://localhost/wordpress/": {
              "clicks": {
                "657 235": 8
              }
            }
          }
        }
      }
    ]
  }
}

Помогите мне решить эту проблему .....

1 Ответ

3 голосов
/ 12 февраля 2020

Поскольку вы проверяете имя поля, а не значение, вы должны попробовать этот запрос вместо

{
    "query": {
        "exists": {
            "field": "target.http://localhost/wordpress/"
        }
    }
}
...