Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v4
with:
dotnet-version: 6.0.x
dotnet-version: 8.0.100
- name: Restore dependencies
run: dotnet restore
- name: Build
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v4
with:
dotnet-version: 6.0.x
dotnet-version: 8.0.100
- name: Restore dependencies
run: dotnet restore
- name: Build
Expand All @@ -24,4 +24,4 @@ jobs:
- name: Pack
run: dotnet pack
- name: Push
run: dotnet nuget push src/Elasticsearch.FSharp/bin/Debug/*.nupkg --api-key ${{secrets.NUGET_API_KEY}} --source https://api.nuget.org/v3/index.json
run: dotnet nuget push src/Elasticsearch.FSharp/bin/Release/*nupkg --api-key ${{secrets.NUGET_API_KEY}} --source https://api.nuget.org/v3/index.json
15 changes: 14 additions & 1 deletion src/Elasticsearch.FSharp/Elasticsearch.FSharp.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,18 @@
<PackageTags>fsharp elastic elasticsearch</PackageTags>
<Description>Compose type-checked ElasticSearch queries with the power of F# language</Description>
<RepositoryUrl>https://github.com/dbarbashov/Elasticsearch.FSharp</RepositoryUrl>
<PackageLicenseUrl>https://github.com/dbarbashov/Elasticsearch.FSharp/blob/master/LICENSE.md</PackageLicenseUrl>
<PackageLicenseFile>LICENSE.md</PackageLicenseFile>
<PackageReadmeFile>readme.md</PackageReadmeFile>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
</PropertyGroup>

<ItemGroup>
<None Include=".\..\..\LICENSE.md" Pack="true" PackagePath=""/>
<None Include=".\..\..\README.md" Pack="true" PackagePath="\"/>
</ItemGroup>

<ItemGroup>
<Compile Include="Utility.fs" />
<Compile Include="DSL\Script.fs" />
Expand Down Expand Up @@ -56,4 +65,8 @@
<InternalsVisibleTo Include="Elasticsearch.FSharp.Tests" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All"/>
</ItemGroup>

</Project>
45 changes: 28 additions & 17 deletions src/Elasticsearch.FSharp/Mapping/Json.fs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
module Elasticsearch.FSharp.Mapping.Json

open System
open System.Runtime.InteropServices
open Elasticsearch.FSharp.Mapping.DSL
open Elasticsearch.FSharp.Utility

let [<Literal>] private OpenSearchFlatObject = "flat_object"

type MappingSetting with
member x.ToJson() =
match x with
Expand All @@ -12,19 +16,25 @@ type MappingSetting with
Json.boolToString value

type PropertyMapping with
member x.ToJson() = Json.makeObject [
member x.ToJson([<Optional; DefaultParameterValue(false)>] usingOpenSearch) = Json.makeObject [
if not x.Enabled then
yield Json.makeKeyValue "enabled" (Json.boolToString x.Enabled)

if x.IgnoreMalformed then
yield Json.makeKeyValue "ignore_malformed" (Json.boolToString x.IgnoreMalformed)

match x.Type with
| Some t -> yield Json.makeKeyValue "type" (Json.quoteString t)
| None -> ()

let ``type`` =
x.Type
|> Option.map(fun t -> if usingOpenSearch && t = "flattened" then OpenSearchFlatObject else t)
|> Option.defaultValue ""

if ``type`` |> String.IsNullOrEmpty |> not then
yield Json.makeKeyValue "type" (Json.quoteString ``type``)

match x.IgnoreAbove with
| Some ia -> yield Json.makeKeyValue "ignore_above" (Json.uintToString ia)
| Some ia ->
if ``type``<> OpenSearchFlatObject then
yield Json.makeKeyValue "ignore_above" (Json.uintToString ia)
| None -> ()

match x.Analyzer with
Expand All @@ -39,21 +49,21 @@ type PropertyMapping with
| Some props ->
yield Json.makeKeyValue "properties" (Json.makeObject [
for p in props do
yield Json.makeKeyValue p.Key (p.Value.ToJson())
yield Json.makeKeyValue p.Key (p.Value.ToJson(usingOpenSearch))
])
| None -> ()

match x.Fields with
| Some fields ->
yield Json.makeKeyValue "fields" (Json.makeObject [
for f in fields do
yield Json.makeKeyValue f.Key (f.Value.ToJson())
yield Json.makeKeyValue f.Key (f.Value.ToJson(usingOpenSearch))
])
| None -> ()
]

type TypeMapping with
member x.ToJson() = Json.makeObject [
member x.ToJson([<Optional; DefaultParameterValue(false)>] usingOpenSearch) = Json.makeObject [
match x.AllEnabled with
| Some true ->
yield
Expand All @@ -64,14 +74,15 @@ type TypeMapping with

yield Json.makeKeyValue "properties" (Json.makeObject [
for p in x.Properties do
yield Json.makeKeyValue p.Key (p.Value.ToJson())
yield Json.makeKeyValue p.Key (p.Value.ToJson(usingOpenSearch))
])
]

type ElasticMapping with
member x.ToJson(?includeTypeName) = Json.makeObject [
let includeTypeName = Option.defaultValue true includeTypeName

member x.ToJson(
[<Optional; DefaultParameterValue(true)>] includeTypeName,
[<Optional; DefaultParameterValue(false)>] usingOpenSearch) = Json.makeObject [

match x.Settings with
| Some settings ->
yield Json.makeKeyValue "settings" (Json.makeObject [
Expand All @@ -82,17 +93,17 @@ type ElasticMapping with

if includeTypeName then
yield Json.makeKeyValue "mappings" (Json.makeObject [
Json.makeKeyValue "_doc" (x.Mappings.ToJson())
Json.makeKeyValue "_doc" (x.Mappings.ToJson(usingOpenSearch))
])
else
yield Json.makeKeyValue "mappings" (x.Mappings.ToJson())
yield Json.makeKeyValue "mappings" (x.Mappings.ToJson(usingOpenSearch))
]

member x.ToPutMappingsJson() = [|
member x.ToPutMappingsJson([<Optional; DefaultParameterValue(false)>] usingOpenSearch) = [|
for kv in x.Mappings.Properties do
yield Json.makeObject [
Json.makeKeyValue "properties" (Json.makeObject [
Json.makeKeyValue kv.Key (kv.Value.ToJson())
Json.makeKeyValue kv.Key (kv.Value.ToJson(usingOpenSearch))
])
]
|]
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<WarningsAsErrors>true</WarningsAsErrors>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FsCheck" Version="2.14.0" />
<PackageReference Include="FsCheck.NUnit" Version="2.14.0" />
<PackageReference Include="nunit" Version="3.11.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.13.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.1" />
<PackageReference Include="FsCheck" Version="2.16.6" />
<PackageReference Include="FsCheck.NUnit" Version="2.16.6" />
<PackageReference Include="nunit" Version="3.14.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading