I would like to get the reference (it means the full object I see in the _source) from where each fragment highlighted originates.
Example :
Table = article
Columns = id, label, content
I would like to know for each fragments highlighted what is the id.
My ElasticSearch request :
GET /sa/_search
{
"query" : {
"bool" : {
"should" : {
"multi_match" : {
"query" : "oasis",
"fields" : [ "label", "content" ]
}
}
}
},
"highlight" : {
"order" : "score",
"fields" : {
"label" : { },
"content" : {
"fragment_size" : 250
}
}
}
}
Currently, with this request, I have only the fragment hightlighted, but I can't know which fragment is link to which id.
Does somebody has any idea to that ?
Related
I am using Swagger Core 2.0 to generate openAPI 3.0 definition files and
I am having trouble to disable "security" for a particular endpoint.
I have my securitySchemes and root security element defined:
{
"openapi" : "3.0.1",
"security" : [ {
"JWT" : [ ]
} ],
"paths" : {
"/auth" : {
"post" : {
"summary" : "authenticate user",
"operationId" : "authenticate",
"requestBody" : {
"content" : {
"application/json" : {
"schema" : {
"$ref" : "#/components/schemas/AuthenticationRequest"
}
}
}
},
"responses" : {
"200" : {
"description" : "when user is successfully authenticated",
"content" : {
"application/json" : {
"schema" : {
"$ref" : "#/components/schemas/AuthenticateUserOutput"
}
}
}
},
"401" : {
"description" : "when email/password not valid or user is blocked/inactive"
}
}
}
},
},
"components" : {
"schemas" : {
"AuthenticateUserOutput" : {
"type" : "object",
"properties" : {
"token" : {
"type" : "string"
},
"lastLoginAt" : {
"type" : "string",
"format" : "date-time"
},
"lastProjectId" : {
"type" : "string"
}
}
},
...,
"AuthenticationRequest" : {
"required" : [ "email", "password" ],
"type" : "object",
"properties" : {
"email" : {
"type" : "string"
},
"password" : {
"type" : "string"
}
}
}
},
"securitySchemes" : {
"JWT" : {
"type" : "http",
"scheme" : "bearer",
"bearerFormat" : "JWT"
}
}
}
}
According to OPEN API 3 spec https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#securityRequirementObject i shall be able to override global "security requirement" for an individual operation. I would like to "disable" JWT security for a few operations and according to https://github.com/OAI/OpenAPI-Specification/blob/3.0.1/versions/3.0.1.md#securityRequirementObject it can be done:
To remove a top-level security declaration, an empty array can be used.
Unfortunately I am struggling to define "empty security array" on Operation level using annotations...
I tried to specify
security = {}
or
security = #SecurityRequirement(name ="")
but no security element within operation is generated at all....
Any idea ?
Below is my java code (i use for swagger dropwizard integration) that allows one to have SecurityScheme and root level security defined
Info info = new Info()
.title("someTitle")
.description("some description")
.version("1.0")
SecurityScheme jwtSecurity = new SecurityScheme()
.type(SecurityScheme.Type.HTTP)
.name("Authorization")
.in(SecurityScheme.In.HEADER)
.scheme("bearer")
.bearerFormat("JWT");
String securitySchemaName = "JWT";
OpenAPI oas = new OpenAPI()
.info(info)
.components(new Components().addSecuritySchemes(securitySchemaName, jwtSecurity))
.addSecurityItem(new SecurityRequirement().addList(securitySchemaName));
SwaggerConfiguration oasConfig = new SwaggerConfiguration()
.openAPI(oas)
.prettyPrint(true)
.resourcePackages(Stream.of("my.resources.package")
.collect(Collectors.toSet()));
environment.jersey().register(new OpenApiResource()
.openApiConfiguration(oasConfig));
Then on a few dedicated endpoints i would like to disable security, so i am trying with:
#POST
#Operation(
summary = "authenticate user",
responses = {
#ApiResponse(responseCode = "200", description = "when user is successfully authenticated",
content = #Content(schema = #Schema(implementation = AuthenticateUserOutput.class))),
#ApiResponse(responseCode = "401", description = "when email/password not valid or user is blocked/inactive"),
}
,security = what to put here ?
)
if you want to do it in yml swagger hub style you can put
security: []
in that endpoint after request body, So swagger considers it as no auth for that particular path or endpoint.
According to a comment over on the OpenAPI-Specifiction GitHub project. It should be possible.
Did you try this?
security: [
{}
]
I had the same problem, on a Java SpringBoot webapp (dependency org.springdoc:springdoc-openapi-ui:1.5.2). As per this answer, I solved it adding an empty #SecurityRequirements annotation on the operation. For example:
#POST
#SecurityRequirements
#Operation(
summary = "authenticate user",
responses = {
#ApiResponse(responseCode = "200", description = "when user is successfully authenticated",
content = #Content(schema = #Schema(implementation = AuthenticateUserOutput.class))),
#ApiResponse(responseCode = "401", description = "when email/password not valid or user is blocked/inactive"),
} )
)
I need to implement stemmer search, I've found this link on elasticsearch documentation. There is json that I've had send to elascticsearch server. But I new in elasticsearch and cannot figure out how to implements this in java. I cannot also find any examples. Ccould you please help me with this?
I've add setting with
PUT /data
{
"settings": {
"analysis" : {
"analyzer" : {
"my_analyzer" : {
"tokenizer" : "standard",
"filter" : ["standard", "lowercase", "my_stemmer"]
}
},
"filter" : {
"my_stemmer" : {
"type" : "stemmer",
"name" : "english"
}
}
}
}
}
after that I am trying to find 'skis' with query:
GET data/_search
{
"query": {
"simple_query_string": {
"fields": [ "value36" ],
"query": "ski"
}
}
}
but result is empty
I am using elasticsearch-1.7.1 and java dependency is
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>1.7.1</version>
Problem : I am using in a clause in ES but when I query ES with filtered query it is giving me a null response.
contentQuery = boolQuery().must(QueryBuilders.matchQuery(PROPERTY_BOOK_ID, bookId).operator(Operator.AND))
.must(QueryBuilders.matchQuery("contentType", "enrichments").operator(Operator.AND))
.must(contentQuery);
FilteredQueryBuilder builder =
QueryBuilders.filteredQuery(contentQuery, FilterBuilders.termFilter("spineId","chapter04.html"));
searchResponse = searchClientService.getClient()
.prepareSearch(INDEX_NAME).setTypes(INDEX_TYPE)
.setQuery(builder)
.execute().actionGet();
without a filter, it is working fine. Can anyone please suggest how to apply a filter to the query or let me know if am going anywhere wrong while making the requests.
Query Details :
{
"filtered" : {
"query" : {
"bool" : {
"must" : [ {
"match" : {
"bookId" : {
"query" : "d563739c-8b46-449b-b695-d662cb32087d",
"type" : "boolean",
"operator" : "AND"
}
}
}, {
"match" : {
"contentType" : {
"query" : "enrichments",
"type" : "boolean",
"operator" : "AND"
}
}
}, {
"bool" : {
"must" : {
"match" : {
"content" : {
"query" : "resources*",
"type" : "phrase_prefix"
}
}
}
}
} ]
}
},
"filter" : {
"term" : {
"spineId" : "chapter04.html"
}
}
}
}
I've also tried other filter queries on my index, none of them is working.Below query must return some result but its returning empty result.
{
"filtered" : {
"query" : {
"match_all" : { }
},
"filter" : {
"bool" : {
"must" : {
"term" : {
"spineId" : "chapter03.html"
}
}
}
}
}
}
Mapping :
private XContentBuilder buildMapping() throws Exception {
return jsonBuilder().prettyPrint()
.startObject()
.startObject(indexType)
.startObject("properties")
.startObject(PROPERTY_SPINE_ID).field("type", "string").field("index", "not_analyzed").endObject()
.endObject()
.endObject()
.endObject();
}
XContentBuilder source = jsonBuilder().startObject();
source.field(PROPERTY_BOOK_ID, bookId)
.field(PROPERTY_WIDGET_ID, widgetId)
.field(PROPERTY_CONTENT, widgetDescription)
.field(PROPERTY_CONTENT_TYPE, contentType.getValue())
.field(PROPERTY_META_DATA, widgetJsonString)
.field(PROPERTY_SPINE_ID, spineId)
.endObject();
any help greatly appreciated.
I'm using #RepositoryRestResource to quickly expose #Entity objects via spring-data-rest.
Question: is it possible to disable any _links self href links from the json response?
"_links" : {
"self" : {
"href" : "http://localhost:8080/people{?page,size,sort}",
"templated" : true
},
"search" : {
"href" : "http://localhost:8080/people/search"
}
},
"_embedded" : {
"persons" : [ {
[...]
I have this query used with Exists API from elasticsearch (1.4.4) :
curl -XPOST 'http://elasticsearch:9200/_search/exists' -d '
{
"query": {
"filtered": {
"query": {
"match_phrase": {
"message": "2014-12-04 00:00:01 CET Tx[XXXXXXXX] cmd[INSERT] PID[XXXX] DB[XXXXX] LOG: some log info here ;-) \r"
}
},
"filter": {
"term" : {
"some_field" :"some_value"
}
}
}
}
}'
This works fine (return true when it has to be) but when I tried to do the same with java API like this :
Client client = this.createClient();
QueryBuilder queryBuilder = QueryBuilders.filteredQuery(
QueryBuilders.matchPhraseQuery("message", "the same message"),
FilterBuilders.termFilter("some_field", "some value")
);
System.out.println(queryBuilder.toString());
ExistsResponse response = client.prepareExists("existsMessage")
.setTypes(type)
.setIndicesOptions(IndicesOptions.fromOptions(true, true, true, false))
.setQuery(queryBuilder).execute().actionGet();
System.out.println(response.exists());
client.close();
But the result is always false! So I print the request build by the and it's different than want I wanted. So is there a way to do exactly my first request from source json or other way using api builders?
Edit :
The output of queryBuilder.toString()) :
{
"filtered" : {
"query" : {
"match" : {
"message" : {
"query" : "the same message\r",
"type" : "phrase"
}
}
},
"filter" : {
"term" : {
"some field" : "some value"
}
}
}
}